简体   繁体   English

js obj应该通过引用传递,但似乎已克隆

[英]js obj supposedly passed by reference, but appears cloned

I have learned that objects in javascript is passed by reference, so if I delete one, they will both be inaccessible. 我了解到javascript中的对象是通过引用传递的,因此,如果我删除一个对象,则它们都将无法访问。

Now, 现在,

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);

that console prints undefined, as expected. 该控制台将按预期方式打印未定义。 However, if I do this: 但是,如果我这样做:

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

It still has the object to present me with, as if it was actually cloned? 它仍然有对象要呈现给我,好像它实际上是克隆的吗?

You deleted the property not the value that property referenced. 您删除了该属性,而不是该属性引用的值。

Other references that value are unaffected. 该值的其他引用不受影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM