Skip to content

Instantly share code, notes, and snippets.

@plugn
Forked from kof/inherits.js
Created January 23, 2013 12:50
Show Gist options
  • Save plugn/4605188 to your computer and use it in GitHub Desktop.
Save plugn/4605188 to your computer and use it in GitHub Desktop.
/**
* Inherit prototype properties
* @param {Function} ctor
* @param {Function} superCtor
*/
_.mixin({
inherits: (function(){
function noop(){}
function ecma3(ctor, superCtor) {
noop.prototype = superCtor.prototype;
ctor.prototype = new noop;
ctor.prototype.constructor = superCtor;
}
function ecma5(ctor, superCtor) {
ctor.prototype = Object.create(superCtor.prototype, {
constructor: { value: ctor, enumerable: false }
});
}
return Object.create ? ecma5 : ecma3;
}())
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment