Skip to content

prefer-this-arg: replace ...(foo.bind(bar)) by ...(foo, bar) #353

Description

@regseb

Description

Check for the methods from, every, filter, find, findIndex, forEach, map and some that the parameter doesn't have a .bind(foo) (and prefer the use of the parameter thisArg).

Example

https://jsbin.com/neleqiwiha/edit?js,console

class Foo {
  #bar = "b";

  filter(element) {
    return this.#bar === element;
  }

  main() {
    console.log(["a", "b", "c"].filter(this.filter.bind(this)));
    console.log(["a", "b", "c"].filter(this.filter, this));
  }
};

const foo = new Foo();
foo.main();

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions