Page 1 of 1

Adjusting and forwarding 'arguments' object

PostPosted: Thu Apr 10, 2008 4:42 pm
by agiletortoise
Is there a way to forward an 'arguments' object to another method?

Currently, if you try to use an arguments object as a passed parameter, it gets wrapped up in another arguments object.

The only workaround I can currently think of is to do something like:

Code: Select all
switch(arguments.length)
{
   case 1: globals[methodName](arguments[0]);break;
   case 2: globals[methodName](arguments[0],arguments[1]);break;
   etc....
}


Any ideas?

greg.

PostPosted: Thu Apr 10, 2008 4:58 pm
by pbakker
Javascript supports the .apply() function, but this is currently not functioning properly in the JavaScript engine Servoy uses.

But, the good news is that it is in Servoy 4.0!

It allows you to apply the Arguments array onto another method.

So, it's either your option now in 3.5 or you can dynamically build a text string like "globals.myMethod(arguments[0],arguments[1], arguments[2])", adding the appropriate number of "arguments[x]" based on the length of the arguments array and then eval that text string.

Paul

PostPosted: Thu Apr 10, 2008 7:57 pm
by agiletortoise
"apply" will be nice to have. I'll make due with the switch statement for now.

greg.