Last active
August 29, 2015 14:14
-
-
Save darlanalves/df6f87bef307f850507d to your computer and use it in GitHub Desktop.
Inheritance helper
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
/** | |
* @param {Function} NewClass | |
* @param {Function} SuperClass | |
* | |
* @example | |
* function Foo() {} | |
* function Bar() { Foo.call(this); } | |
* inherits(Bar, Foo); | |
*/ | |
var inherits = function (NewClass, SuperClass, attributes) { | |
var prototype = SuperClass.prototype, | |
childPrototype = Object.create(prototype); | |
Object.keys(attributes).forEach(function (key) { | |
childPrototype[key] = attributes[key]; | |
}); | |
NewClass.prototype = childPrototype; | |
NewClass.prototype.constructor = NewClass; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment