禁止函数赋值
注意:此规则是
recommended
规则集的一部分。在
deno.json
中启用完整集合{ "lint": { "rules": { "tags": ["recommended"] } } }
使用 Deno CLI 启用完整集合
deno lint --rules-tags=recommended
通过将此规则添加到
deno.json
中的 include
或 exclude
数组,可以显式地将其包含到当前标签中的规则或从中排除。{ "lint": { "rules": { "include": ["no-func-assign"], "exclude": ["no-func-assign"] } } }
禁止覆盖/重新赋值现有函数。
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; // variable reassignment, not function re-declaration