Skip to content
← Back to rules

eslint/no-extra-bind 懸念

An auto-fix is available for this rule.

何をするか

不要な .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);

使用方法

設定ファイルまたは CLI でこのルールを有効化するには、以下のように使用できます:

json
{
  "rules": {
    "no-extra-bind": "error"
  }
}
bash
oxlint --deny no-extra-bind

参照