at.*_*at. 4 javascript arguments function
我有一个JavaScript函数:
function test() {
console.log(arguments.length);
}
Run Code Online (Sandbox Code Playgroud)
如果我打电话给它test(1,3,5),它打印出来,3因为有3个参数.如何从另一个函数中调用test并传递其他函数的参数?
function other() {
test(arguments); // always prints 1
test(); // always prints 0
}
Run Code Online (Sandbox Code Playgroud)
我想调用other它test并使用它的arguments数组调用它.
看看apply():
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply
function other(){
test.apply(null, arguments);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4400 次 |
| 最近记录: |