0
看一看这段JavaScript代码:分配操作是否总是从右向左复制数据?
var myString = new String();
myString.myObject = "myObject...";
//works fine as it shows "myObject..."
console.log("myString.myObject :" + myString.myObject);
//OK myObject is also a string so it should give length and it works fine
console.log("myString.myObject.length :" + myString.myObject.length);
//it should not give anything or undefined since nothing is given to myString
console.log("myString :" + myString);
//myString is not yet defined so it should give undefined or 0..
console.log("myString.length :" + myString.length);
//lets make a simple assignment
myString = myString.myObject;
//it should just copy value of myObject to myString so there are two copies of string "myObject.."
//lets log all the data all the data as i did above
console.log("myString.myObject :" + myString.myObject);
//and this part is giving error
//console.log("myString.myObject.length :" + myString.myObject.length);
console.log("myString :" + myString);
console.log("myString.length :" + myString.length);
在上半年(赋值之前),它正在为我所预期,但转让之后它给出了一个错误。
看来myString.myObject
在分配后被删除。是吗?。
当我尝试访问myString.myObject
时,控制台出现红色错误。分配删除myString.myObject
,还是发生在这里?