The `arguments` object changes if parameters change

二次信任 提交于 2020-01-14 01:38:55

问题


I just discovered that the arguments object actually changes if one of the parameters change.

For example:

function some(a, b, c ){
  console.log(arguments);


  args = [ a, b, c ];
  a = new Date();

  console.log(arguments);
  console.log(args);
}

some(1,2,3 );

You will see that while args stays the same (expected behaviour), arguments actually change.

Questions:

  • Is this something that is well documented? If so, where?

  • Is there anything else I need to be careful about the arguments object?


回答1:


This is specified in the ECMA standard sec-10.6:

For non-strict mode functions [...] the number of formal parameters of the corresponding function object initially share their values with the corresponding argument bindings in the function’s execution context. This means that changing the property changes the corresponding value of the argument binding and vice-versa. This correspondence is broken if such a property is deleted and then redefined or if the property is changed into an accessor property. For strict mode functions, the values of the arguments object’s properties are simply a copy of the arguments passed to the function and there is no dynamic linkage between the property values and the formal parameter values.



来源:https://stackoverflow.com/questions/21493562/the-arguments-object-changes-if-parameters-change

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!