-
-
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)
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
/** | |
* 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; | |
}()) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.