https://github.com/joyent/node/blob/master/lib/util.js#L410
This correctly sets this.constructor on instances of any subclass.
https://github.com/joyent/node/blob/master/lib/util.js#L410
This correctly sets this.constructor on instances of any subclass.
Instead, use a function like this:
var inherits = function(child, parent) {
var ctor = function(){};
ctor.prototype = parent.prototype;
child.prototype = new ctor;
ctor.prototype.constructor = child;
};In my test case crockford's create is seemingly faster for this, but I'm sure I'm missing something. Someone mind educating me here?
After calling this function, the child constructor's prototype is an object with no own properties, which itself has the parent's prototype, so references to properties of the parent's prototype will resolve and objects created using the child constructor will return true for "instanceof parent".
The other step usually involved, which isn't shown here, is to put `Parent.call(this)` (with any necessary arguments) in the child constructor.