如果`arguments`对象更改参数的变化 [英] The `arguments` object changes if parameters change

查看:172
本文介绍了如果`arguments`对象更改参数的变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚发现,如果其中一个参数修改参数对象实际上改变。

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

例如:

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 );

您将看到,虽然 ARGS 保持不变(预期的行为),参数实际改变。

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

问题:


  • 难道这东西,是有据可查?如果是这样,在哪里?

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

还有什么我需要小心有关参数对象?

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

推荐答案

这是在ECMA标准中规定的仲10.6

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.

这篇关于如果`arguments`对象更改参数的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆