About synchronizing the Emcsscript internal parameters with the parameter list

Source: Internet
Author: User

This article thinks about this issue after reading the Professional JavaScript for WEB developers 3rd Edition section on Understanding Parameters .

The author mentions in the book that the named parameter (Assignment) as a function parameter is passed inside the function, essentially passing the value into the arguments array inside the function, defining the index of the named parameter in the array in the order in which it is passed in.

The value of the named parameter is synchronized with the value of the corresponding part of the arguments array, that is, when the value of the named parameter changes, the value of the corresponding part of the arguments array is changed accordingly. In addition, the authors emphasize that the two parts of the space in memory are independent, so they will only synchronize with each other, but within the space does not affect.

The following code tests can conclude that the above conclusions are correct: (Test environment: Chrome 43.0.2357.134 m/windows 7 Ultimate)

1 functionsumto (num) {2Alert (arguments[0]+ "/" +num);3Num=12;4Alert (arguments[0]+ "/" +num);5Arguments[0]=15;6Alert (arguments[0]+ "/" +num);7             }8Sumto ();//returns three sets of values: UNDEFINED/UNDEFINED;UNDEFINED/12;15/129Sumto (10);//returns three sets of values: 10/10;12/12;15/15

The above code also explains two questions:

1. When a named parameter is defined without passing in a parameter to a function, arguments returns undefined as a named parameter, such as a variable that defines an unassigned value.

2. The values of both sides will change if the value of the named parameter or the value of the corresponding part of the arguments is modified in the function.

Here, Conclusion 2 is the author's negation in the book, the author writes: But this effect is unidirectional, modifying the named parameter does not change the corresponding value in the arguments. Of course, the author of the whole book corresponding to Emcascript, the author did not fully read the EMCAScript-262, temporarily unable to judge the correctness of the conclusion, only from the test results, this effect is not one-way.

About synchronizing the Emcsscript internal parameters with the parameter list

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.