In the Javascript code below I create 2 instances of Person (p1
and p2
).
When changing the name of p1
, only the name of p1
is changed (and not the name of p2
). This is exactly what I expect.
But when changing p1.sizes.width
and then checking the value of p2.sizes.width
, it appears that p1.sizes.width
is equal to p2.sizes.width
.
Why?
var Person = {
name: '',
sizes: {width: {type:'size', value:undefined}, height: {type:'size', value:undefined}}
}
var p1 = Object.create(Person);
var p2 = Object.create(Person);
p1.name = "Alice";
p2.name = "Bob";
console.log(p1.name === "Alice") // true
console.log(p2.name === "Bob") // true
p1.sizes.width=20;
console.log(p1.sizes.width === 20) // true
console.log(p2.sizes.width === 20) // true (but I would had expected false...?!)