function test(arg1, arg2, arg3) { console.log(arguments); // arguments类数组对象 Arguments [Array(7), callee... console.log(test.length); // 3 形参个数 console.log(arguments.length); // 7 实参个数 console.log(arguments.callee); // 指向当前执行的函数 f... // 转换为一个真正的Array, 需要接收一下 类数组使用 ... 扩展成真正的 数组 console.log(...arguments); // 1, 2, 3, 4, 5, 6, 7 console.log(Object.prototype.toString.call(...arguments)); // [object Number] // arguments 对象只能在函数内使用 console.log(Object.prototype.toString.call(arguments)); // "[object Arguments]" console.log(arguments[0], arguments[1]); // 1 2 console.log(typeof arguments[0]); // number // 对参数使用扩展语法 // 使用Array.from()方法或扩展运算符将参数转换为真实数组: var args = Array.from(arguments); console.log(args); var args = [...arguments]; console.log(args); // 更改 arguments[1] arguments[0] = 666; console.log(arguments[0]); // 666 } let arr = [1, 2, 3, 4, 5, 6, 7]
test(...arr)