var foo = {x: 1}
var bar = {__proto__: foo} // __proto__ specific to implementation
var bar = Object.create(foo) // same result as above with standard API
console.log(bar.x) // 1
foo.x = 2
console.log(bar.x) // 2
bar.x = 3
console.log(foo.x) // 2
Why did updating the inherited
property x
by the child object bar
take no effect on the parent object foo
but the opposite do?
@EDIT
After its creation the child own
property remains unaffected when the parent object updates the shadowed
property now.
foo.x = 4
console.log(bar.x) // 3