Skip to content

Instantly share code, notes, and snippets.

@prust
Forked from kof/inherits.js
Last active December 19, 2015 09:49
Show Gist options
  • Save prust/5936064 to your computer and use it in GitHub Desktop.
Save prust/5936064 to your computer and use it in GitHub Desktop.
Updated to match the latest version in node (added writeable: true, configurable: true, which have been in node since 0.4.9 https://github.com/joyent/node/commit/1ba2c321, also added `super_` which has been in node since the beginning, apparently)
/**
* Inherit prototype properties
* @param {Function} ctor
* @param {Function} superCtor
*/
_.mixin({
inherits: (function(){
function noop(){}
function ecma3(ctor, superCtor) {
noop.prototype = superCtor.prototype;
ctor.super_ = superCtor;
ctor.prototype = new noop;
ctor.prototype.constructor = ctor;
}
function ecma5(ctor, superCtor) {
ctor.super_ = superCtor;
ctor.prototype = Object.create(superCtor.prototype, {
constructor: {
value: ctor,
enumerable: false,
writable: true,
configurable: true
}
});
}
return Object.create ? ecma5 : ecma3;
}())
});
@prust
Copy link
Author

prust commented Oct 9, 2014

FYI: I just discovered https://github.com/isaacs/inherits, which has an identical implementation to this fork but should be preferred because it is in a github repo, is maintained and is used by browserify.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment