Disallow unnecessary function binding (no-extra-bind)

The --fix option on the command line can automatically fix some of the problems reported by this rule.

The bind() method is used to create functions with specific this values and, optionally, binds arguments to specific values. When used to specify the value of this, it’s important that the function actually use this in its function body. For example:

In this code, the reference to this has been removed but bind() is still used. In this case, the bind() is unnecessary overhead (and a performance hit) and can be safely removed.

Rule Details

This rule is aimed at avoiding the unnecessary use of bind() and as such will warn whenever an immediately-invoked function expression (IIFE) is using bind() and doesn’t have an appropriate this value. This rule won’t flag usage of bind() that includes function argument binding.

Note: Arrow functions can never have their this value set using bind(). This rule flags all uses of bind() with arrow functions as a problem