Arguments object (Object/core)

An object represented as an array containing the argument values passed to the function when it is called.

Availability:

ECMAScript edition - 2
JavaScript - 1.1
JScript - 5.5
Internet Explorer - 5.5
Netscape - 3.0
JavaScript syntax:-myArguments = arguments
Object properties:callee, caller, length

When you call a function, you can pass zero or more arguments to it from outside. These arguments are available as named variables whose name is defined in the function declaration.

However, they are also available as the elements in an array. The arguments array is referenced by the arguments property of the call object. Since the call object is added to the scope chain, you don't need to reference the arguments property with an object identifier prefix.

The array based mechanism is useful for those times when you want to implement a function that has a variable number of arguments passed to it according to how and when it is called.

A new arguments object is created for each execution context. When the flow of control enters an execution context for a function block, a new arguments object is created. Declared functions, anonymous code and implementation-specific code all use this technique.

When creating the arguments object, the initial conditions are set up like this:

Note that objects of this type can only exist within a function body in a web browser, because you cannot pass parameters to a script from outside. It is possible that an embedded JavaScript interpreter may provide a host object to the main entry point to perform the same function.

Warnings:

Example code:

   
   <SCRIPT>
   // Call a function and use its arguments array find out the
   // name of the function that called it.  Demonstrates a one
   // level call tracer.
   
   level1();
   
   function level1()
   {
      testArgs(1, "ONE", true);
   }
   
   function testArgs(a1, a2,a3)
   {
      document.write(callerName(arguments));
      document.write("<BR>");
   }
   
   function callerName(a1)
   {
      myCallerObject = a1.caller.callee;
      myCallerSource = String(myCallerObject);
      mySplitArray1  = myCallerSource.split(" ");
      mySplitArray2  = mySplitArray1[1].split("(");
      myCaller       = mySplitArray2[0];
      return(myCaller);
   }
   </SCRIPT>

See also:Argument, Argument list, Arguments.callee, Arguments.caller, Arguments.length, arguments[], Collection object, Execution context, Function arguments, Function call, Function call operator ( ), function( ... ) ..., Function.arguments[], Object inspector, Object.prototype, Parameter

PropertyJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
callee1.2 1.25.5 5.54.0 4.05.5 5.5 n/a n/a n/a n/a n/a n/aDontEnum.
caller1.1 1.15.5 5.53.0 3.05.5 5.5 n/a n/a n/a n/a n/a n/aWarning , DontEnum., Deprecated
length1.1 1.15.5 5.53.0 3.05.5 5.5 n/a n/a n/a n/a n/a n/aReadOnly, DontEnum.

Cross-references:

ECMA 262 edition 2 - section - 10.1.6

ECMA 262 edition 2 - section - 10.1.8

ECMA 262 edition 2 - section - 15.2.3.1

ECMA 262 edition 3 - section - 10.1.6

ECMA 262 edition 3 - section - 10.1.8

Wrox Instant JavaScript - page - 27