问题描述
我刚刚发现,如果其中一个参数发生变化,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
保持不变(预期行为),arguments
实际上 发生了变化.
You will see that while args
stays the same (expected behaviour), arguments
actually change.
问题:
这是有据可查的吗?如果有,在哪里?
Is this something that is well documented? If so, where?
对于 arguments
对象还有什么需要注意的吗?
Is there anything else I need to be careful about the arguments
object?
推荐答案
这是在 ECMA 标准中指定的 sec-10.6:
This is specified in the ECMA standard sec-10.6:
对于非严格模式函数 [...] 形式参数的数量相应的函数对象最初与函数执行中对应的参数绑定语境.这意味着改变属性会改变参数绑定的对应值,反之亦然.这个如果这样的属性被删除,然后通信就会被破坏重新定义或如果该属性更改为访问器属性.为了严格模式函数,参数对象的属性值只是传递给函数的参数的副本,并且有财产价值和形式价值之间没有动态联系参数值.
这篇关于如果参数改变,`arguments` 对象也会改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!