deno.com

no-func-assign

注意: 此规则是 recommended 规则集的一部分。
deno.json 中启用完整规则集:
{
  "lint": {
    "rules": {
      "tags": ["recommended"]
    }
  }
}
使用 Deno CLI 启用完整规则集:
deno lint --rules-tags=recommended

禁止覆盖/重新分配现有函数。

Javascript 允许重新分配函数定义。这通常是开发人员的错误,或者是糟糕的编码实践,因为代码的可读性和可维护性会受到影响。

无效示例:

function foo() {}
foo = bar;

const a = function baz() {
  baz = "now I'm a string";
};

myFunc = existingFunc;
function myFunc() {}

有效示例:

function foo() {}
const someVar = foo;

const a = function baz() {
  const someStr = "now I'm a string";
};

const anotherFuncRef = existingFunc;

let myFuncVar = function () {};
myFuncVar = bar; // 变量重新分配,不是函数重新声明

你找到需要的内容了吗?

隐私政策