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