Can anyone explain this code to me
var ParentClass = function(){
}
var ChildClass = function(){
}
//ChildClass.prototype = new ParentClass();
var child = new ChildClass();
alert(child.constructor === ChildClass); // alert true
But
var ParentClass = function(){
}
var ChildClass = function(){
}
ChildClass.prototype = new ParentClass();
var child = new ChildClass();
alert(child.constructor === ChildClass); // alert false
constructoris a property of theprototypeobject:The relationship is now like this:
This property points indeed to the
ChildClassfunction.If you override
ChildClass.prototype, thenchild.constructorwill be looked up in the prototype chain and will refer to:as
ChildClass.prototypeis now an instance ofParentClasswhich inherits fromParentClass.prototype:ParentClass.prototype.constructorwill of course point toParentClass.