Share via


arguments Object

An object representing the currently executing function, its arguments, and the function that called it. This object cannot be constructed explicitly.

Properties

arguments Object Properties

Methods

The arguments object has no methods.

Requirements

Version 1

Remarks

An arguments object is instantiated for each function when it begins execution. The arguments object is directly accessible only within the scope of its associated function.

All parameters passed to a function and the number of parameters are stored in the arguments object. The arguments object is not an array, but the individual arguments are accessed using [ ] notation, the same way array elements are accessed.

You can use the arguments object to create functions that can accept an arbitrary number of arguments. This functionality can also be achieved by using the parameter array construction when defining your function. For more information, see the function statement topic.

Note

The arguments object is not available when running in fast mode, the default for JScript. To compile a program from the command line that uses the arguments object, you must turn off the fast option by using /fast-. It is not safe to turn off the fast option in ASP.NET because of threading issues.

Example

The following example illustrates the use of the arguments object.

function argTest(a, b) : String {
   var i : int;
   var s : String = "The argTest function expected ";
   var numargs : int = arguments.length; // Get number of arguments passed.
   var expargs : int = argTest.length;   // Get number of arguments expected.
   if (expargs < 2)
      s += expargs + " argument. ";
   else
      s += expargs + " arguments. ";
   if (numargs < 2)
      s += numargs + " was passed.";
   else
      s += numargs + " were passed.";
   s += "\n"
   for (i =0 ; i < numargs; i+){        // Get argument contents.
      s += "  Arg " + i + " = " + arguments[i] + "\n";
   }
   return(s);                            // Return list of arguments.
}

print(argTest(42));
print(argTest(new Date(1999,8,7),"Sam",Math.PI));

The output of this program is:

The argTest function expected 2 arguments. 1 was passed.
  Arg 0 = 42

The argTest function expected 2 arguments. 3 were passed.
  Arg 0 = Tue Sep 7 00:00:00 PDT 1999
  Arg 1 = Sam
  Arg 2 = 3.141592653589793

See Also

Reference

new Operator

function Statement

/fast