Adjusting and forwarding 'arguments' object

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

Adjusting and forwarding 'arguments' object

Postby agiletortoise » Thu Apr 10, 2008 4:42 pm

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.
Greg Pierce
Agile Tortoise
SAN Developer
http://www.agiletortoise.com
User avatar
agiletortoise
 
Posts: 278
Joined: Wed Oct 12, 2005 3:26 pm
Location: Texas, USA

Postby pbakker » Thu Apr 10, 2008 4:58 pm

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
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Postby agiletortoise » Thu Apr 10, 2008 7:57 pm

"apply" will be nice to have. I'll make due with the switch statement for now.

greg.
Greg Pierce
Agile Tortoise
SAN Developer
http://www.agiletortoise.com
User avatar
agiletortoise
 
Posts: 278
Joined: Wed Oct 12, 2005 3:26 pm
Location: Texas, USA


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 6 guests