Created
September 19, 2012 20:22
-
-
Save dbrans/3752000 to your computer and use it in GitHub Desktop.
Javascript: Chain the prototypes of Parent and Child functions
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
// Chain the prototypes of Parent and Child functions. | |
function chainPrototypes (Parent, Child) { | |
// Create the link to Parent's prototype | |
var ChildPrototype = function(){}; | |
ChildPrototype.prototype = Parent.prototype; | |
Child.prototype = new ChildPrototype(); | |
// Setup the proper constructor for 'instances' of Child. | |
Child.prototype.constructor = Child; | |
// Return "super" | |
return Parent.prototype; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment