Arrow functions cannot be bound

  • USELESS_ARROW_FUNC_BIND
  • Code Quality
  • Low
  • es6

This rule applies when an arrow function is bound.

Arrow functions are always bound with the this object of the context at which the function is defined, and it cannot be changed.
Therefore, the attempt to bind arrow functions with calling bind() or call() has no effect.

Noncompliant Code Example

View with compliant examples side by side
function Adder(base) {
    this.base = base;

    var add = (a) => {
        return this.base + a;
    };

    this.addBase = function (baseObj, a) {
        return add.call(baseObj, a); // USELESS_ARROW_FUNC_BIND alarm because the bound function 'add' is an arrow function.
    };
}

var adder = new Adder(1);
adder.addBase({ base: 2 }, 2); // Return value is 3

Compliant Code Example

View with noncompliant examples side by side
function Adder(base) {
    this.base = base;

    var add = (a) => {
        return this.base + a;
    };

    this.addBase = function (baseObj, a) {
        this.base = baseObj.base;
        return add(a);
    };
}

var adder = new Adder(1);
adder.addBase({ base: 2 }, 2); // Return value is 4

Version

This rule was introduced in DeepScan 1.11.0-beta.

See