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