Skip to content

noUselessBind (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"noUselessBind": "error"
}
}
}
}

Disallow unnecessary .bind() calls on functions.

Calling .bind() on a function creates a new function with a fixed value for this. When the function never uses this, the call does nothing useful: it only makes the code harder to read and creates an extra function at runtime.

Arrow functions always use the this of the code around them, so calling .bind() on an arrow function can’t change this either.

This rule only reports .bind() calls with a single argument. Calls with more arguments also fix the values of the first parameters, so they still have an effect.

const x = function () {
foo();
}.bind(bar);
code-block.js:3:3 lint/nursery/noUselessBind  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This bind() call is unnecessary.

1 │ const x = function () {
2 │ foo();
> 3 │ }.bind(bar);
│ ^^^^
4 │

ℹ This function doesn't use this, so binding it has no effect.

ℹ Remove the bind() call and use the function directly.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Unsafe fix: Remove the bind() call.

3 │ }.bind(bar);
│ ----------
const x = (() => {
this.foo();
}).bind(bar);
code-block.js:3:4 lint/nursery/noUselessBind  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This bind() call is unnecessary.

1 │ const x = (() => {
2 │ this.foo();
> 3 │ }).bind(bar);
│ ^^^^
4 │

ℹ Arrow functions always use the this of the code around them, so bind() can't change it.

ℹ Remove the bind() call and use the function directly.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Unsafe fix: Remove the bind() call.

3 │ }).bind(bar);
│ ----------
const x = function () {
(function () {
this.foo();
})();
}.bind(bar);
code-block.js:5:3 lint/nursery/noUselessBind  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This bind() call is unnecessary.

3 │ this.foo();
4 │ })();
> 5 │ }.bind(bar);
│ ^^^^
6 │

ℹ This function doesn't use this, so binding it has no effect.

ℹ Remove the bind() call and use the function directly.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Unsafe fix: Remove the bind() call.

5 │ }.bind(bar);
│ ----------
const a = function () {
this.foo();
}.bind(bar);
const b = function () {
(() => this.foo())();
}.bind(bar);
const c = function (a) {
return a + 1;
}.bind(bar, 1);