Skip to content

Instantly share code, notes, and snippets.

@dbrans
Created September 19, 2012 20:22
Show Gist options
  • Save dbrans/3752000 to your computer and use it in GitHub Desktop.
Save dbrans/3752000 to your computer and use it in GitHub Desktop.
Javascript: Chain the prototypes of Parent and Child functions
// 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