我认为如果第二个表达式评估为false
指向chineseBox
前面定义的空对象会更自然。
它不再是空的了。截至chineseBox.content = chineseBox
,它现在有一个属性。
当您将对象引用分配给事物(变量、属性等)时,存储的值是对对象的引用,而不是对象的副本。所以chineseBox
(变量)和chineseBox.content
(属性)都指向同一个对象,它有一个名为 的属性content
。
让我们在这里抛出一些 ASCII 艺术:
var chineseBox = {};
这给了我们:
+−−−−−−−−−−−−−−−−−−−−−−−−−−+
| chineseBox (变量) |
+−−−−−−−−−−−−−−−−−−−−−−−−−−+ +−−−−−−−−−−−−−−−−+
| 值 |−−−−−−−−−−>| (对象) |
+−−−−−−−−−−−−−−−−−−−−−−−−−−+ +−−−−−−−−−−−−−−−−+
| |
+−−−−−−−−−−−−−−−−−+
现在我们做
chineseBox.content = chineseBox;
...我们有:
/−−−−−−−−−−−−\
+−−−−−−−−−−−−−−−−−−−−−−−−−+ | |
| chineseBox (变量) | v |
+−−−−−−−−−−−−−−−−−−−−−−−−−−+ +−−−−−−−−−−−−−−−−+ |
| 值 |−−−−−−−−−−>| (对象) | |
+−−−−−−−−−−−−−−−−−−−−−−−−−−+ +−−−−−−−−−−−−−−−−+ |
| 内容 |−−−−/
+−−−−−−−−−−−−−−−−−+
只有一个对象。有两个参考文献指向它。