我想使用数组作为参数来调用函数:
const x = ['p0', 'p1', 'p2'];
call_me(x[0], x[1], x[2]); // I don't like it
function call_me (param0, param1, param2 ) {
// ...
}
Run Code Online (Sandbox Code Playgroud)
有路过的内容的一种更好的方式x进入call_me()?
我可以在JavaScript中以方便的方式调用带有参数数组的函数吗?
例:
var fn = function() {
console.log(arguments);
}
var args = [1,2,3];
fn(args);
Run Code Online (Sandbox Code Playgroud)
我需要的arguments是[1,2,3],就像我的数组.