arguments.length Property | Flash 5 |
the number of parameters passed to an argument | read/write |
The length property stores an integer representing the number of elements in the arguments array, which equates to the number of parameters passed to the currently executing function.
We can use the length property of arguments to determine whether a function was invoked with the correct number of parameters. The following example checks whether two arguments have been passed to someFunction( ). Checking whether the passed arguments are of the correct type is left as an exercise to the reader. (Hint: see the typeof operator.) Here's the code:
function someFunction (y, z) { if (arguments.length != 2) { trace("Function invoked with wrong number of parameters"); return; } // Proceed with normal function body... }