Browser/User Agent Support
| IE | Mozilla | Netscape | Opera | Safari | 4.0+ | 1.0+ | 3.0+ | 7.0+ | 1.0+ |
|---|
Constructors
| Constructor | IE | Mozilla | Netscape | Opera | Safari |
|---|---|---|---|---|---|
Creates a new instance of the Arguments array. | 4.0+ | 1.0+ | 3.0+ | 7.0+ | 1.0+ |
Properties
| Property | IE | Mozilla | Netscape | Opera | Safari |
|---|---|---|---|---|---|
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.0 | 3.0+ | no | no |
Number of arguments passed to the function. | 4.0+ | 1.0+ | 3.0+ | 7.0+ | 1.0+ |
References
Availability
JavaScript 1.1 | JScript 2.0 | ECMAScript v1
Constructor Detail
Property Detail
String callee
Name of the function being executed.
Example: Using
arguments.calleein an anonymous recursive functionA 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
Functionconstructor.) This is wherearguments.calleecomes 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
calleeis a property of the arguments local variable available within all function objects;calleeas a property ofFunction.argumentsis no longer used. (Function.argumentsitself is also deprecated.)arguments.calleeallows anonymous functions to refer to themselves, which is necessary for recursive anonymous functions.The
thiskeyword does not refer to the currently executing function. Use thecalleeproperty 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.callerin a functionThe following code checks the value of
arguments.callerin 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.callercan no longer be used. Use the non-standardcallerproperty of the function instead.The
callerproperty 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
calleris null.The
thiskeyword does not refer to the currently executing function, so you must refer to functions andFunctionobjects by name, even within the function body.The
callerproperty 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).
- If you use it in a string context, you get the result of calling
- Availability
JavaScript 1.2 | Deprecated by JavaScript 1.3
Number length
Number of arguments passed to the function.
- See Also
- Availability
JavaScript 1.1 | JScript 2 | ECMAScript v1