JavaScript implements continuous assignment _javascript techniques

Source: Internet
Author: User

Recent project contact, time is more adequate, to browse the Internet and stumbled on the Internet to find this problem, the predicted results and the real result is too big.

Please look at the following code

var a={n:1}
var b=a;
A.x=a={n:2}
Console.log (a.x); 
Console.log (b.x);
Undefined
Object{n:2}

If we take the code apart, 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}

JS assignment operation is right combination, above equivalent to a.x= (A={n:2})

JS evaluation operation is from left to right (PS: and colleagues discuss, he said is from left to right, I think it is from right to left, and finally found that I was wrong)

1) a.x= (final result in parentheses)

To find the X property of a that does not exist, add an attribute x to the object that a points to, and this X property assigns a result to it, well, I'm waiting for the result.

2) Because the result is to get the results in parentheses, then a.x is waiting to return the result in parentheses, so start the evaluation A={n:2} and return to the new property X

3) Back to the parentheses in the a={n:2},a occurred pointing to change the

JavaScript implementation gives <a href= "" > Href assignment

document.getElementById ("a"). href= ""; A is the ID of the hyperlink A that you want to add, such as <a id= ' a ' > info tip </a>
<form action= "" method= "Post" name= "MyForm" >
<a href = "" Id=links > Info </a >
</form >
<script >
document.getElementById ("links"). href= " Http://www.baidu.com ";
</script >

This code content implementation to <a hre= "" >href assignment, how the code is very simple.

The above content is this article uses the JavaScript to realize continuously assigns the value the entire content, hoped that has the help to everybody, this website has the new content renewal every day, continues to pay attention yo!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.