eslint/no-extra-bind Suspicious
它的作用
禁止不必要地调用 .bind()。
为什么这不好?
该规则旨在避免不必要地使用 bind(), 因此,当立即调用函数表达式(IIFE)使用了 bind() 并且没有合适的 this 值时,它会发出警告。 该规则不会标记包含函数参数绑定的 bind() 用法。
示例
以下是此规则的错误代码示例:
js
const x = function () {
foo();
}.bind(bar);
const z = (() => {
this.foo();
}).bind(this);以下是此规则的正确代码示例:
js
const x = function () {
this.foo();
}.bind(bar);
const y = function (a) {
return a + 1;
}.bind(foo, bar);如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"rules": {
"no-extra-bind": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
rules: {
"no-extra-bind": "error",
},
});bash
oxlint --deny no-extra-bind版本
此规则是在 v1.1.0 中添加的。
