Name

arguments.length Property — the number of parameters passed to an argument

Availability

Flash 5

Synopsis

arguments.length

Access

Read/write

Description

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.

Example

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...
}

Get ActionScript: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.