Training Course Title Record 3

Source: Internet
Author: User

I suggest that you first go to your own browser to try, found that the results do not match what you want to come back to see the following content.
The same is the source of the first release:
As before, the key section is marked with the serial number, so let's get started.
Don't look at the function body part of the setobj, wait until it is called for the first time. We p= from var. Here to start looking.
var p={name: "Xixi", age:24} This paragraph declares that a global variable p leads an object, let's say the object is a.  Then we throw p to the Setobj function: Setobj (p); OK, start executing this function:
Because the address of object A is stored in P, ① is going to assign the address of P stored outside the function to the local variable of the function: O, and the address of a in O. In other words, if we operate on O, then we will operate on a. There are two variables in the program: the P under window and the local variable o within the active object of the SetObject function.
② assigns an empty object to O. At this point, O no longer points to a, instead pointing to an empty object, let's say that this object is B.
③ creates a new property name for the new empty object B above, and assigns a value of small red.

Finally Console.log (p); Now, think about it, p from the beginning to the present, have you let go of the object it was pointing at? No, it's not. P has been attracting object A from beginning to end. And only one thing happened to object a: ① there to change the value of its name. If you don't understand why P always leads a please look at the Blue Word section again.

So the output is:
=========================================================================================================
The second part of the code is just less than the above ②③ two steps, just skipped.



———— The above content are my original, welcome to discuss in the comment area, the article to correct. If you need to reprint, please contact the Blogger to obtain the consent, and note the reprint source Bo main mailbox: [email protected]

Training Course Title Record 3

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.