Created
September 2, 2013 15:57
-
-
Save cybrown/6414405 to your computer and use it in GitHub Desktop.
Javascript Prototype Inheritance
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
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