1.
function MyConstructor() {}
var myobject = new MyConstructor();
MyConstructor.prototype = {protest:"maizere"};
[ myobject instanceof MyConstructor, // false !
myobject.constructor == MyConstructor, // true !
myobject instanceof Object ] // true
console.log(myobject.protest) //undefined
This proves that myobject does not inherit properties and method from MyConstructor prototype anymore.
But see next code below:
2.
function MyConstructor() {}
var myobject = new MyConstructor();
MyConstructor.prototype.protest= "Maizere";//Do this line gets hoisted?or something else
[ myobject instanceof MyConstructor, // true!
myobject.constructor == MyConstructor, // true !
myobject instanceof Object ] // true
console.log(myobject.protest) //Maizere
Why is this happening?what is the exact definition of internal prototype?This also proves even after the instantiation of the object , proto is refering to MyConstructor prototype.If so than why the first(1.) code not referring to MyConstructor prototype? since the property is being added after the instantiation of an object in the second code and the internal prototype of the object receives it ,this means we can change the prototype properties later and still see the effect in the instance .But same definition is not working when prototype properties is replaced in the first code?