是否可以在不使用 Array
的情况下将多个(未知)参数传递给函数?
看看这个示例代码。
var test = function( /* Arguments */ ) { // Number 3
something( /* All Arguments Here */ );
};
var something = function( first, last, age ) { // Number 2
alert( first + last + age );
};
test('John', 'Smith', 50); // Number 1
所以问题...
Is it possible to pass the parameters from
Number 1
TONumber 2
VIANumber 3
without affecting the way it's used. ie. without anArray
.
这可能与 OCD
有关,但使用数组看起来会很难看。
我试过什么了吗? 不,我想不出什么可以尝试的……我可以尝试什么?我已经搜索过了......
最佳答案
var test = function() { // Number 3 something.apply(null, arguments); }; var something = function( first, last, age ) { // Number 2 alert( first + last + age ); }; test('John', 'Smith', 50); // Number 1
关于javascript - 通过函数将多个参数传递给函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17920090/