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]); }
show
has defined arguments, it does not usearguments
. I have already triedapply
that way with no luck. – steveo225apply
is the only way to do this, therefore it is a duplicate. – Felix Klingarguments
used was entirely different and ultimately the point of the question. – steveo225