When a prototype is set on a constructor function, the instanceof
operator only returns true
until the prototype is changed. Why?
function SomeConstructorFunction() {
}
function extendAndInstantiate(constructorFn) {
constructorFn.prototype = {}; //Can be any prototype
return new constructorFn();
}
var child1 = extendAndInstantiate(SomeConstructorFunction);
console.log(child1 instanceof SomeConstructorFunction); //true
var child2 = extendAndInstantiate(SomeConstructorFunction);
console.log(child1 instanceof SomeConstructorFunction); //false
console.log(child2 instanceof SomeConstructorFunction); //true