-
-
Save nw/711126 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add a handy super call for all objects | |
MyBaseClass.prototype.super = function () { | |
var parent = this.__proto__.__proto__; | |
var caller = arguments.callee.caller; | |
var fn; | |
if (caller.prototype === this.__proto__) { | |
return parent.constructor.apply(this, arguments); | |
} else { | |
// This is probably quite slow, but it doesn't seem to affect | |
// performance too much in real tests. | |
var keys = Object.keys(this.__proto__); | |
for(var i=0, l = keys.length; i < l; i++){ | |
if(this.__proto__[keys[i]] === caller) | |
return parent[keys[i]].apply(this, arguments); | |
} | |
} | |
}; | |
MyBaseClass.adopt = function (child) { | |
child.__proto__ = this; | |
child.prototype.__proto__ = this.prototype; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment