Use of arguments.caller / arguments.callee
ID |
javascript.no_caller |
Severity |
high |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Reliability |
Language |
JavaScript |
Tags |
best-practice, reliability |
Description
Reports access to arguments.caller and arguments.callee. Both are deprecated, throw in strict mode (ECMAScript 5+ / ES modules), and inhibit engine optimisations.
Rationale
arguments.caller and arguments.callee are vestigial properties from the early days of JavaScript:
-
In strict mode (and inside ES modules / class bodies, which are strict by default), reading either of them throws a
TypeError. -
Their presence forces engines to materialise extra stack-frame metadata, blocking tail-call elimination and inlining.
-
They tie functions to caller/callee identity in ways that break refactoring tools and obfuscators.
// Bad - throws in strict mode, prevents JIT optimisations
function fact(n) {
return n <= 1 ? 1 : n * arguments.callee(n - 1);
}
Remediation
Use a named function reference for recursion, or refactor into a named function expression.
// Good - named recursion
function fact(n) {
return n <= 1 ? 1 : n * fact(n - 1);
}
// Good - named function expression
const fact = function fact(n) {
return n <= 1 ? 1 : n * fact(n - 1);
};