aboutsummaryrefslogtreecommitdiffstats
path: root/lib/utils.js
diff options
context:
space:
mode:
authorjez2011-01-04 16:51:58 +0800
committerjez2011-01-04 16:52:47 +0800
commitbbf078cf0a3bff06a9fc2172b3b63e1198a42c4e (patch)
treef50b75cfcbca8084a846c364037b0e2e4fd714a7 /lib/utils.js
parent4bf8f199cd3685b58f08a25601b6adc067029c60 (diff)
downloadvimium-bbf078cf0a3bff06a9fc2172b3b63e1198a42c4e.tar.bz2
Comments and renaming.
Diffstat (limited to 'lib/utils.js')
-rw-r--r--lib/utils.js19
1 files changed, 14 insertions, 5 deletions
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;
},