Created
October 16, 2011 09:24
-
-
Save ewinslow/1290701 to your computer and use it in GitHub Desktop.
Inheritance + super access in javascript
This file contains 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
inherit = function(Child, Parent) { | |
Child.prototype = new Parent(); | |
Child.prototype.constructor = Child; | |
Child.prototype.super_ = function(methodName) { | |
// Special case: calling from constructor | |
if (arguments.caller.callee.prototype.super_) { | |
return Parent.apply(this, arguments); | |
} | |
var varArgs = Array.prototype.slice.call(arguments, 1); | |
return Parent.prototype[methodName].apply(this, varArgs); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment