Index

no-caller

禁止使用 arguments.callerarguments.callee

arguments.callerarguments.callee 的使用使得若干代码优化变得不可能。它们在未来的 JavaScript 版本中已被弃用,并且在 ECMAScript 5 的严格模式下禁止使用。

🌐 The use of arguments.caller and arguments.callee make several code optimizations impossible. They have been deprecated in future versions of JavaScript and their use is forbidden in ECMAScript 5 while in strict mode.

function foo() {
    const callee = arguments.callee;
}

规则详情

🌐 Rule Details

该规则旨在通过禁止使用 arguments.callerarguments.callee 来阻止使用已弃用和次优代码。因此,当使用 arguments.callerarguments.callee 时,它会发出警告。

🌐 This rule is aimed at discouraging the use of deprecated and sub-optimal code by disallowing the use of arguments.caller and arguments.callee. As such, it will warn when arguments.caller and arguments.callee are used.

此规则的错误代码示例:

🌐 Examples of incorrect code for this rule:

在线运行
/*eslint no-caller: "error"*/

function foo(n) {
    if (n <= 0) {
        return;
    }

    arguments.callee(n - 1);
}

[1,2,3,4,5].map(function(n) {
    return !(n > 1) ? 1 : arguments.callee(n - 1) * n;
});

符合此规则的正确代码示例:

🌐 Examples of correct code for this rule:

在线运行
/*eslint no-caller: "error"*/

function foo(n) {
    if (n <= 0) {
        return;
    }

    foo(n - 1);
}

[1,2,3,4,5].map(function factorial(n) {
    return !(n > 1) ? 1 : factorial(n - 1) * n;
});

选项

🌐 Options

此规则没有选项。

🌐 This rule has no options.

版本

此规则是在 ESLint v0.0.6 中引入。

资源