aboutsummaryrefslogtreecommitdiffstats
path: root/lib/utils.js
diff options
context:
space:
mode:
authorjez2011-01-03 04:29:12 +0800
committerjez2011-01-03 04:31:30 +0800
commitbaf3dd02d5891df9a35af7d2f8f2eaa42ac6bb03 (patch)
tree82e23247feff463e24033529ad56217c47846147 /lib/utils.js
parentca2996d06c883a1f8449e8c77b7168345dbdb529 (diff)
downloadvimium-baf3dd02d5891df9a35af7d2f8f2eaa42ac6bb03.tar.bz2
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.
Diffstat (limited to 'lib/utils.js')
-rw-r--r--lib/utils.js32
1 files changed, 32 insertions, 0 deletions
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;
+ },
+};