From bbf078cf0a3bff06a9fc2172b3b63e1198a42c4e Mon Sep 17 00:00:00 2001 From: jez Date: Tue, 4 Jan 2011 16:51:58 +0800 Subject: Comments and renaming. --- lib/utils.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'lib/utils.js') diff --git a/lib/utils.js b/lib/utils.js index 86c868b8..4c05610c 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,5 +1,7 @@ var utils = { - deepcopy: function(original) { + // probably doesn't handle some cases correctly, but it works fine for what + // we have now + deepCopy: function(original) { var result; if (typeof original == 'object') { if (original === null) { @@ -8,7 +10,7 @@ var utils = { result = original.constructor === Array ? [] : {}; for (var i in original) if (original.hasOwnProperty(i)) - result[i] = this.deepcopy(original[i]); + result[i] = this.deepCopy(original[i]); } } else { result = original; @@ -16,16 +18,23 @@ var utils = { return result; }, + + /* + * Extends 'original' with 'ext'. If a function in 'ext' also exists in + * 'original', let the 'original' function be accessible in the new object + * via a ._super(functionName as String) method. _Cannot_ be used on its + * result to achieve 'two-level' inheritance. + */ extendWithSuper: function(original, ext) { - var result = this.deepcopy(original); + 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]); + result._superFunctions[i] = this.deepCopy(original[i]); + result[i] = this.deepCopy(ext[i]); } return result; }, -- cgit v1.2.3