Skip to content

Instantly share code, notes, and snippets.

@darlanalves
Last active August 29, 2015 14:14
Show Gist options
  • Save darlanalves/df6f87bef307f850507d to your computer and use it in GitHub Desktop.
Save darlanalves/df6f87bef307f850507d to your computer and use it in GitHub Desktop.
Inheritance helper
/**
* @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