4 ms·
Person will also have anything you add to Spy's prototype if you do that. Attaching the "parent" prototype you want to have in the "child" prototype chain to a
by insin 14y ago
Person will also have anything you add to Spy's prototype if you do that.
Attaching the "parent" prototype you want to have in the "child" prototype chain to a dummy constructor and new-ing that will do the trick for widest compatibility, although Object.create in ES5 and __proto__ (standardised) in ES6 both give you more direct access to the prototype chain:
function inherits(child, parent) {
var dummy = function() {}
dummy.prototype = parent.prototype
child.prototype = new dummy()
child.prototype.constructor = child
}
function Spy() {
Person.apply(this, arguments)
}
inherits(Spy, Person)