この 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
、それとも何か他のことがここで起こっていますか?