A few days ago in search of the face of the test to find such a piece of code, after the implementation of the feeling is completely not the same as the
var a = {
n:1
};
var b = A;
a.x = a = {N:2};
Console.log (a.x);
Console.log (b.x);
The output results are:
Undefined
[Object Object]
At first, the statement should be assigned a value of {N:2} first, and then the a.x assignment {N:2};
But the fact is not like that, so changed the code, add a few log
var test;
var a = {get
Test () {
console.log ("called a Get");
return test;
},
set test (value) {
Console.log (' Call a set ');
Test = value;
}
}
var test2;
var B = {get
test2 () {
console.log ("called B Get");
return test2;
},
set Test2 (value) {
Console.log (' call B Set ');
Test2 = value;
}
}
A.test = {
n:1
};
B.test2 = a.test;
Console.log ("Begin");
A.test.x = A.test = {N:2};
Thus, at the end of the begin, the value of the assignment is at a glance.
This is the log that is printed when the statement is executed
A get is triggered first, and set is triggered once.
I guess the order in which the statement was executed was to take the left variable out first and then perform the assignment. (Take the object reference out before executing the statement, and then execute the assignment from right to left)
The above mentioned is the entire content of this article, I hope you can enjoy