据推测js obj通过引用传递,但似乎克隆了

时间:2014-02-26 12:02:27

标签: javascript jquery object

我已经了解到javascript中的对象是通过引用传递的,所以如果我删除它们,它们都将无法访问。

现在,

var self = self.parent.modules[moduleId].slideshow;

delete self.parent.modules[moduleId].slideshow; //remove the module object from the JSON

console.error('deleted self. it is now:');                
console.error(self.parent.modules[moduleId].slideshow);

控制台按预期打印undefined。但是,如果我这样做:

console.error('deleted self. it is now:');                
console.error(self);

它还有向我展示的对象,好像它实际上是克隆过的一样?

1 个答案:

答案 0 :(得分:1)

您删除了属性而不是属性引用的值。

其他参考值不受影响。