关于arguments的新理解

0次阅读

共计 380 个字符,预计需要花费 1 分钟才能阅读完成。

function test(a, b){
arguments[0] = 1
arguments[1] = 9
console.log(“a”,a); //1
console.log(“b”,b); //undefined
console.log(“ 形参长度 ”,test.length); //2
console.log(“ 实参长度 ”,arguments.length); //1
console.log(“ 实参数组 ”,arguments); //[1,9]
}
test(2);

我很不懂为什么 b 是 undefined 呢?既然 a 能重新赋值,为啥 b 不能?
本来我是认为 a,b 分别对应 arguments[0] 和 arguments[1],经过一番研究这是不完全正确的
arguments 第一个值就是 a,b 没有传值没有存储到 arguments,无论 arguments 怎样赋值 b 都是 undefind。终于解决了心头大石

正文完
 0