Why are the properties of an instance that stores primitive values, not references, updated when the prototype is updated if the property was not set by the instance itself?
Let me give an example:
var Obj = function () {};
Obj.prototype.num = 1;
var myObj = new Obj();
var myOtherObj = new Obj();
console.log(myObj.num);
console.log(myOtherObj.num);
Obj.prototype.num = 3;
console.log(myObj.num);
console.log(myOtherObj.num);
myObj.num += 2;
console.log(myObj.num);
console.log(myOtherObj.num);
Obj.prototype.num = 4;
console.log(myObj.num);
console.log(myOtherObj.num);
A couple of weird things here:
After creating the instance, updating the class definition updates the value of the instance if and only if it has never been updated by the instance itself.
, , num, , , ( this.num instanceName.num) .
, ECMA5:
prototype [[Prototype]] , Function .
, internal [[Prototype]], . , , , , , , , .