function with arguments

Discuss all feature requests you have for a new Servoy versions here. Make sure to be clear about what you want, provide an example and indicate how important the feature is for you

function with arguments

Postby Ron » Tue Aug 26, 2008 11:56 am

I downloaded a piece of JS code that I want to run in my method.
It appears that v.4 not supports functions with arguments, like:

function product(a,b)
{
a * b
}

function callproduct()
(
answer = product(3,2)
)

This would be realy nice to have.

Regards,
Ron
Ron
 
Posts: 315
Joined: Fri May 23, 2003 12:30 am
Location: Netherlands

Re: function with arguments

Postby Joas » Tue Aug 26, 2008 12:07 pm

Why not use the arguments-array?

Code: Select all
function product()
{
   var a = arguments[0];
   var b = arguments[1];

   return a * b;
}

function callproduct()
{
   var answer = product(3,2);
}
Joas de Haan
Yield Software Development
Need help on your project? yieldsd.com
User avatar
Joas
Site Admin
 
Posts: 842
Joined: Mon Mar 20, 2006 4:07 pm
Location: Leusden, NL

Re: function with arguments

Postby Ron » Tue Aug 26, 2008 1:31 pm

Thanks for the code Joas, in fact it does the same thing.
Problem stays however that I have to rebuilt available
JS code with function arguments.

Regards,
Ron
Ron
 
Posts: 315
Joined: Fri May 23, 2003 12:30 am
Location: Netherlands

Re: function with arguments

Postby pbakker » Tue Aug 26, 2008 8:54 pm

Functions with named arguments is on the todo list...

Paul
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Re: function with arguments

Postby agiletortoise » Tue Aug 26, 2008 10:44 pm

You can define it with named arguments dynamically, like this...
Code: Select all
function my_global_init_function() {
   globals['product'] = function(a,b) {
      return a*b;
   }
}


Then you be able to call "globals.product(1,2)" in your code. Just be sure your init function is called before you intend to use it (like in your solution open method).

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 Discuss Feature Requests

Who is online

Users browsing this forum: No registered users and 17 guests