no-func-assign
NOTE: this rule is part of the
推荐 rule set.Enable full set in
deno.json:{
"lint": {
"rules": {
"tags": ["推荐"]
}
}
}Enable full set using the Deno CLI:
deno lint --rules-tags=推荐
This rule can be explictly included to or excluded from the rules present in the current tag by adding it to the
include or exclude array in deno.json:{
"lint": {
"rules": {
"include": ["no-func-assign"],
"exclude": ["no-func-assign"]
}
}
}不允许重写/重新赋值已有函数。
Javascript 允许对函数定义进行重新赋值。这通常是开发者的错误,或者编码实践不佳,因为代码的可读性和可维护性将受到影响。
无效示例:
function foo() {}
foo = bar;
const a = function baz() {
baz = "现在我是一串字符串";
};
myFunc = existingFunc;
function myFunc() {}
有效示例:
function foo() {}
const someVar = foo;
const a = function baz() {
const someStr = "现在我是一串字符串";
};
const anotherFuncRef = existingFunc;
let myFuncVar = function () {};
myFuncVar = bar; // 变量重新赋值,不是函数重新声明