How does javascript realize continuous assignment? The following section describes how to use javascript to realize continuous assignment. If you need continuous assignment, you can refer to the recent project contacts. The time is sufficient, I visited the Internet and accidentally found this problem on the Internet. The predicted results differ greatly from the actual ones.
See the following code.
var a={n:1}var b=a;a.x=a={n:2}console.log(a.x); console.log(b.x);undefinedObject{n:2}
If we split the code, the result is what we think.
var a={n:1}var b=a;a={n:2};a.x={n:2}console.log(a.x);//Object{n:2}console.log(b.x);//undefined
Analysis Code:
A. x = a = {n: 2}
The value assignment operation of js is a combination of the right, which is equivalentA. x = (a = {n: 2 })
Evaluate JavaScript code from left to right(PS: I discussed it with my colleague. He said it was from left to right. I thought it was from right to left. I finally found that I was wrong)
1) a. x = (final result in parentheses)
After finding that the x attribute of a does not exist, add a property x to the object pointed to by a. The x attribute will assign a result to it. Well, I will wait for the result.
2) to obtain the result in parentheses,. x is always waiting for the result to be returned to him in parentheses, so the new property x is returned after obtaining the result from a = {n: 2 }.
3) return to a = {n: 2} in the brackets, and a is changed.
Assign a value to href using javascript.
Document. getElementById ("a"). href = ""; a is the id of the hyperlink a to be added, such as the Information prompt
Information prompt
The content of this code is used to assign values to href. How is the code simple.
The above content is all the content of continuous assignment using javascript in this article. I hope it will be helpful to you. New content is updated on this site every day and you will continue to pay attention to it!