Possible Duplicate:
Is it possible to send a variable number of arguments to a JavaScript function?
I can use arguments
to get a variable number of arguments within a function, but how can I pass them to another function without knowing its prototype?
function show(foo, bar) { window.alert(foo+' '+bar); }
function run(f) { f(arguments); } // not correct, what to do?
run(show, 'foo', 'bar');
Note: I cannot guarantee the number of arguments needed for the function f
that is passed to run
. Meaning, even though the example shown has 2 arguments, it could be 0-infinite, so the following isn't appropriate:
function run(f) { f(arguments[1], arguments[2]); }