I have a function in JavaScript:
function test() {
console.log(arguments.length);
}
如果我使用
test(1,3,5)
调用它,它会打印出3
,因为有3个参数。如何从另一个函数中调用test并传递另一个函数的参数?function other() {
test(arguments); // always prints 1
test(); // always prints 0
}
我希望调用
other
函数,并让它使用自己的arguments
数组来调用test
函数。请注意,保留HTML标记。
test.apply(this, arguments);
。 - Michael Lortonthis
。 - FabianCook