User Guide
100 ActionScript Language and Syntax
ActionScript 3.0 allows function calls to include more parameters than those defined in the
function definition, but will generate a compiler error in strict mode if the number of
parameters is less than the number of required parameters. You can use the array aspect of the
arguments object to access any parameter passed to the function, whether or not that
parameter is defined in the function definition. The following example uses the
arguments
array along with the
arguments.length property to trace all the parameters passed to the
traceArgArray() function:
function traceArgArray(x:int):void
{
for (var i:uint = 0; i < arguments.length; i++)
{
trace(arguments[i]);
}
}
traceArgArray(1, 2, 3);
// output:
// 1
// 2
// 3
The arguments.callee property is often used in anonymous functions to create recursion.
You can use it to add flexibility to your code. If the name of a recursive function changes over
the course of your development cycle, you need not worry about changing the recursive call in
your function body if you use
arguments.callee instead of the function name. The
arguments.callee property is used in the following function expression to enable recursion:
var factorial:Function = function (x:uint)
{
if(x == 0)
{
return 1;
}
else
{
return (x * arguments.callee(x - 1));
}
}
trace(factorial(5)); // 120
If you use the ... (rest) parameter in your function declaration, the arguments object will not
be available to you. Instead, you must access the parameters using the parameter names that
you declared for them.