没有矛盾。只是不要考虑嵌套对象:对象的直接属性总是在其原型上或在自己的属性上。属性值是否为基元或对象与无关紧要。
所以,当你这样做
var parent = { x: {a:0}};var child = Object.create(parent);child.x将引用与
parent.x-一个
{a:0}对象相同的对象。当您更改其属性时:var prop_val = child.x; // == parent.xprop_val.a = 1;
两者都会受到影响。要独立更改“嵌套”属性,您首先必须创建一个独立的对象:
child.x = {a:0};child.x.a = 1;parent.x.a; // still 0你能做的是
child.x = Object.create(parent.x);child.x.a = 1;delete child.x.a; // (child.x).a == 0, because child.x inherits from parent.xdelete child.x; // (child).x.a == 0, because child inherits from parent
which means they are not absolutely independent - but still two different
objects.



