The expected results are very different from the actual results when I accidentally discovered this problem on the Internet.
var a={n:1}var b=a;ax=a={n:2}console.log(ax); console.log(bx); undefinedObject{n:2}If I take apart, the result will be what I thought
var a={n:1}var b=a;a={n:2};ax={n:2}console.log(ax);//Object{n:2}console.log(bx);//undefinedanalyze:
ax=a={n:2}
The assignment operation of js is combined with the right, which is equivalent to ax=(a={n:2})
The evaluation operation of js is from left to right (PS: Discussed with a colleague, he said it was from left to right, and I thought it was from right to left, but in the end I found that I was wrong)
1) ax=(final result in brackets)
After finding that the x attribute of a does not exist, add an attribute x to the object pointed to by a. This x attribute needs to assign a result to it. OK, I'll wait for the result.
2) Because you want to get the result in brackets, ax keeps waiting for the result in brackets to return it, so you start evaluating a={n:2} and then return it to this new attribute x
3) Return to a={n:2} in brackets, the pointing change occurred
The simple implementation of continuous js assignment above is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.