I find the behaviour of this piece of code puzzling, why is the constructor of child
not Child
? Can someone please explain this to me?
function Parent() {
this.prop1 = "value1";
this.prop2 = "value2";
}
function Child() {
this.prop1 = "value1b";
this.prop3 = "value3";
}
Child.prototype = new Parent();
var child = new Child();
// this is expected
console.log(child instanceof Child); //true
console.log(child instanceof Parent); //true
// what??
console.log(child.constructor == Child); //false
console.log(child.constructor == Parent); //true