Skip to content

Instantly share code, notes, and snippets.

@cybrown
Created September 2, 2013 15:57
Show Gist options
  • Save cybrown/6414405 to your computer and use it in GitHub Desktop.
Save cybrown/6414405 to your computer and use it in GitHub Desktop.
Javascript Prototype Inheritance
var Parent = function (arg1, arg2) {
// TODO Define instance members here...
};
Parent.prototype.doSomething = function (arg) {
// TODO Do something...
};
var Child = function (arg1, arg2) {
Parent.call(this, arg1, arg2) // Call to super constructor
// TODO Define instance members here...
};
Child.prototype = Object.create(Parent.prototype);
Child.prototype.doSomething = function (arg) {
Parent.prototype.doSomething(arg); // Call to super method
// TODO Do something else ?
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment