[英]Why assigning textContent to a reference does not update the DOM when reference is changed?
It looks like textContent is a property in Node, but why the below code doesn't work as expected: 看起来textContent是Node中的一个属性,但为什么下面的代码不能按预期工作:
http://jsbin.com/ukexab/1/edit http://jsbin.com/ukexab/1/edit
var d = document.getElementById("container");
var data = {text: "something different"};
d.textContent = data.text;
data.text = "new text";
Is this something like copying and not referencing? 这是复制而不是引用吗?
Yes, it's due to how assignment works. 是的,这是由于作业如何运作。
Assigning an Object
or anything derived from it to a variable will actually assign a reference to that object, and increase the object's reference count. 将Object
或从中派生的任何内容分配给变量实际上将分配对该对象的引用,并增加对象的引用计数。
Assigning a primitive will pass a copy of its value. 分配基元将传递其值的副本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.