From baf3dd02d5891df9a35af7d2f8f2eaa42ac6bb03 Mon Sep 17 00:00:00 2001 From: jez Date: Mon, 3 Jan 2011 04:29:12 +0800 Subject: Revise how the linkHints object is generated. Add lib/utils.js. Extend a template object rather than using prototype inheritance. The previous method created confusion about whether a given property resided in the base or in the specialization. --- lib/utils.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 lib/utils.js (limited to 'lib/utils.js') diff --git a/lib/utils.js b/lib/utils.js new file mode 100644 index 00000000..86c868b8 --- /dev/null +++ b/lib/utils.js @@ -0,0 +1,32 @@ +var utils = { + deepcopy: function(original) { + var result; + if (typeof original == 'object') { + if (original === null) { + result = null; + } else { + result = original.constructor === Array ? [] : {}; + for (var i in original) + if (original.hasOwnProperty(i)) + result[i] = this.deepcopy(original[i]); + } + } else { + result = original; + } + + return result; + }, + extendWithSuper: function(original, ext) { + var result = this.deepcopy(original); + var tmpSuper = result._super; + result._superFunctions = {}; + result._super = function(fname) { return this._superFunctions[fname].bind(this); } + for (var i in ext) + if (ext.hasOwnProperty(i)) { + if (typeof ext[i] == 'function' && typeof original[i] == 'function') + result._superFunctions[i] = this.deepcopy(original[i]); + result[i] = this.deepcopy(ext[i]); + } + return result; + }, +}; -- cgit v1.2.3