Javascript Implementation of continuous assignment _ javascript tips-js tutorial

Source: Internet
Author: User
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!

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.