Arguments : Object

An array of parameters passed to a function.

Browser/User Agent Support

IEMozillaNetscapeOperaSafari
4.0+1.0+3.0+7.0+1.0+

Constructors

ConstructorIEMozillaNetscapeOperaSafari
Creates a new instance of the Arguments array.
4.0+1.0+3.0+7.0+1.0+
 

Properties

PropertyIEMozillaNetscapeOperaSafari
Name of the function being executed.
5.5+1.0+4.0+7.0+no
 
Name of the function that called the function being executed.
4.0+1.03.0+nono
 
Number of arguments passed to the function.
4.0+1.0+3.0+7.0+1.0+
 

References

Function

Availability

JavaScript 1.1 | JScript 2.0 | ECMAScript v1

Constructor Detail

Arguments Arguments()

Creates a new instance of the Arguments array.

Visibility
internal

Property Detail

String callee

Name of the function being executed.

Example: Using arguments.callee in an anonymous recursive function

A recursive function must be able to refer to itself. Typically, a function refers to itself by its name. However, an anonymous function does not have a name, and if there is no accessible variable referring to it, i.e. the function is not assigned to any variable, the function cannot refer to itself. (Anonymous functions can be created by a function expression or the Function constructor.) This is where arguments.callee comes in.

The following example defines a function, which, in turn, defines and returns a factorial function.

function makeFactorialFunc() {
   alert('making a factorial function!');
   return function(x) {
      if (x <= 1)
         return 1;
      return x * arguments.callee(x - 1);
   };
}

var result = makeFactorialFunc()(5); // returns 120 (5 * 4 * 3 * 2 * 1)
Remarks

callee is a property of the arguments local variable available within all function objects; callee as a property of Function.arguments is no longer used. (Function.arguments itself is also deprecated.)

arguments.callee allows anonymous functions to refer to themselves, which is necessary for recursive anonymous functions.

The this keyword does not refer to the currently executing function. Use the callee property to refer to a function within the function body.

Availability

JavaScript 1.2 | Deprecated by JavaScript 1.4 | JScript 5.5 | ECMAScript v1

String caller - read only

Name of the function that called the function being executed.

Example: Checking the value of arguments.caller in a function

The following code checks the value of arguments.caller in a function.

function myFunc() {
   if (arguments.caller == null) {
      return ("The function was called from the top!");
   } else
      return ("This function's caller was " + arguments.caller);
}
Remarks

arguments.caller can no longer be used. Use the non-standard caller property of the function instead.

The caller property is available only within the body of a function.

If the currently executing function was invoked by the top level of a JavaScript program, the value of caller is null.

The this keyword does not refer to the currently executing function, so you must refer to functions and Function objects by name, even within the function body.

The caller property is a reference to the calling function, so:

  • If you use it in a string context, you get the result of calling functionName.toString, i.e. the decompiled canonical source form of the function.
  • You can also call the calling function, if you know what arguments it might want. Thus, a called function can call its caller without knowing the name of the particular caller, provided it knows that all of its callers have the same form and fit, and that they will not call the called function again unconditionally (which would result in infinite recursion).
Availability

JavaScript 1.2 | Deprecated by JavaScript 1.3

Number length

Number of arguments passed to the function.

See Also

Array.length | Function.length

Availability

JavaScript 1.1 | JScript 2 | ECMAScript v1