Skip to content

Instantly share code, notes, and snippets.

@ewinslow
Created October 16, 2011 09:24
Show Gist options
  • Save ewinslow/1290701 to your computer and use it in GitHub Desktop.
Save ewinslow/1290701 to your computer and use it in GitHub Desktop.
Inheritance + super access in javascript
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