S
Sergey Emantayev
Hi everyone,
I need to call a 3rd party's function which accepts a variable number
of arguments. I have the parameters packed in an array so I need to
call it like Func(params[0], params[1], params[2]...). The problem is
that the array may have a different length and I need to pass the
array somehow instead of comma delimeted param list.
I have a nasty solution by passing a dynamically generated call string
to eval( ) like following:
var params = ... // an array containing the function arguments.
var s = 'Func(';
for (i in params)
{
if (i > 0)
{
s += ',';
}
s += "'"+params+"'";
}
s += ')';
eval(s);
Is there a more elegant way to fix that?
Like (this does not work...) -
Func.arguments = params;
Func();
Regards,
Sergey Emantayev
I need to call a 3rd party's function which accepts a variable number
of arguments. I have the parameters packed in an array so I need to
call it like Func(params[0], params[1], params[2]...). The problem is
that the array may have a different length and I need to pass the
array somehow instead of comma delimeted param list.
I have a nasty solution by passing a dynamically generated call string
to eval( ) like following:
var params = ... // an array containing the function arguments.
var s = 'Func(';
for (i in params)
{
if (i > 0)
{
s += ',';
}
s += "'"+params+"'";
}
s += ')';
eval(s);
Is there a more elegant way to fix that?
Like (this does not work...) -
Func.arguments = params;
Func();
Regards,
Sergey Emantayev