Page 1 of 1

function with arguments

PostPosted: Tue Aug 26, 2008 11:56 am
by Ron
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

Re: function with arguments

PostPosted: Tue Aug 26, 2008 12:07 pm
by Joas
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);
}

Re: function with arguments

PostPosted: Tue Aug 26, 2008 1:31 pm
by Ron
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

Re: function with arguments

PostPosted: Tue Aug 26, 2008 8:54 pm
by pbakker
Functions with named arguments is on the todo list...

Paul

Re: function with arguments

PostPosted: Tue Aug 26, 2008 10:44 pm
by agiletortoise
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.