var myObject = new Object();
var myObjectCopy = myObject;
myObject.Name = 'alav';
// logs Name alav on both variable
console.log(myObject, myObjectCopy);
myObject = null;
// logs myObject as null and myObjectCopy still has name 'alav' -> bcoz of reference copy
console.log(myObject, myObjectCopy);
下面没有复制相同的行为。
var objA = {property: 'value'};
var pointer1 = objA;
// update the objA.property, and all references (pointer1 & pointer2) are updated
objA.property = pointer1.property;
objA.property= null;
// logs 'null null' because objA, pointer1 all reference the same object
console.log(objA.property, pointer1.property);
为什么上述引用复制行为不适用于对象的内部属性(此处为属性)?
objA.property = 指针1.property;-> 不是参考副本吗?