Description
Creates a new function.
Syntax
Parameters
Remarks
Syntax 1 is the standard way to create new functions in Ffish Script. Syntax 2 is an alternative form used to create function objects explicitly. Ffish script also support nested functions. A nested function object is a function placed in another function, it will become a member of the Object object constructed by the outer function. For example, we create an object to calculate the square roots:
function GetRoot(value)
{
this.value = value;
function root()
{
return Math.sqrt(this.value);
}
}
gr = new GetRoot(4);
trace(gr.root());
//output: 2
an alternative version:
function GetRoot(value)
{
function root(value)
{
return Math.sqrt(value);
}
return GetRoot.root(value);
}
trace(GetRoot(4));
//output: 2
Example
For example, to create a function that calculates summation of three numbers, you can do it in either of two ways:
//Example 1
function sum(x, y, z){ return x + y + z;}
//Example 2
var sum = new Function("x, y", "z",
"return(x+y+z)");
//In either case,
//you call the function with a line of code similar
//to the following:
sum(1, 2, 3);