arguments.callee
Deprecated
Avoid using this feature in new projects.
JavaScript strict mode prohibits accessing arguments.callee.
This feature may be a candidate for removal from web standards or browsers.>
Note:
Accessing arguments.callee in strict mode will throw a TypeError. If a function must reference itself, either give the function expression a name or use a function declaration.
The arguments.callee data property contains the currently executing function that the arguments belong to.
Value
A reference to the currently executing function.
Property attributes of arguments.callee | |
|---|---|
| Writable | yes |
| Enumerable | no |
| Configurable | yes |
Note:
callee is a data property only in non-strict functions with simple parameters (in which case the arguments object is also auto-syncing). Otherwise, it is an accessor property whose getter and setter both throw a TypeError.
Description
callee is a property of the arguments object. It can be used to refer to the currently executing function inside the function body of that function. This is useful when the name of the function is unknown, such as within a function expression with no name (also called "anonymous functions").
(The text below is largely adapted from a Stack Overflow answer by olliej)
Early versions of JavaScript did not allow named function expressions, and for this reason you could not make a recursive function expression.
For example, this syntax worked:
function factorial(n) {
return n <= 1 ? 1 : factorial(n - 1) * n;
}
[1, 2, 3, 4, 5].map(factorial);
but:
[1, 2, 3, 4, 5].map(function (n) {
return n <= 1 ? 1 : /* what goes here? */ (n - 1) * n;
});
did not. To get around this arguments.callee was added so you could do