function Entity() {
this.a = {a: 4};
this.b = 5;
}
function Thing() {}
Thing.prototype = new Entity;
var thing1 = new Thing;
thing1.a.a = 3;
thing1.b = 4;
var thing2 = new Thing;
console.log(thing2.a.a);
console.log(thing2.b)
I find it hard to set prototypal inheritance in javascript. Ideally, I want both thing1 and thing2 to have their own clean copy of the โnew Entity prototypeโ.
use this.__proto__is what i want to avoid
[edit]
I have a general idea of โโhow this works.
Setting thing1.b sets property b in the Thing instance. which does not apply to Entity.b defined in the prototype chain.
If the installation of the thing1.aa object on the Thing instance cannot be completed, because this will cause a "can not set a on undefined" error. It is then that he rises up the prototype chain to find Entity.a, which is defined and sets Entity.aa to a new value.
[ ]
@IvoWetzel, thing1.b , . , thing1.a.a . thing1.a, , .a