gpt4 book ai didi

javascript - 如果参数更改,则 `arguments` 对象也会更改

转载 作者:行者123 更新时间:2023-11-29 18:17:50 25 4
gpt4 key购买 nike

我刚刚发现,如果其中一个参数发生变化,arguments 对象实际上会发生变化。

例如:

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 实际上 发生了变化。

问题:

  • 这是有据可查的吗?如果有,在哪里?

  • 对于 arguments 对象,还有什么我需要注意的吗?

最佳答案

这是在 ECMA 标准中指定的 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.

关于javascript - 如果参数更改,则 `arguments` 对象也会更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21493562/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com