Node js 中通过 arguments 对象修改/增加参数的方法
function foo() {
console.log(arguments);
console.log(arguments['extra']);
}
foo.apply({}, {'0':'arg_1', '1':'arg_2', length: 2});
// { '0': 'arg_1', '1': 'arg_2' }
// undefined
foo.apply({}, {'0':'arg_1', '5':'arg_2', length: 2});
// { '0': 'arg_1', '1': undefined }
// undefined
foo.apply({}, {'0':'arg_1', 'extra':'arg_2', length: 2});
// { '0': 'arg_1', '1': undefined }
// undefined
foo.apply({}, {'0':'arg_1', '1':'arg_2', length: 1});
// { '0': 'arg_1' }
// undefined
- 无法在 arguments 中传递自己命名的属性. 无法通过 apply(this, argumenst) 传递到被调用函数中.
- key 必须是数字
- length 属性需要和与最大的 key 值相对应, 否则, 长于 length 的参数无法传递