1.0.3 • Published 6 years ago

class-methods-binder v1.0.3

Weekly downloads
3
License
Apache-2.0
Repository
github
Last release
6 years ago

Class-Methods-Binder

License

Install

npm install class-methods-binder

The standard way to bind the method.

class Example {
  constructor() {
    this.handleClick = this.handleClick.bind(this);
    this.handleChange = this.handleChange.bind(this);
  }

  handleClick() {}

  handleChange() {}
}

Non-standard way to bind the method.

class Example {
  constructor() {}

  handleClick = () => {};

  handleChange = () => {};
}

Usage

"class-methods-binder" is an easy and standart way to bind the method.

import binder from "class-methods-binder";

class Example {
  constructor() {
    binder(this);
  }

  handleClick() {}

  handleChange() {}
}

Advanced Usage

Only bind internal methods.

import binder from "class-methods-binder";

class Example {
  constructor() {
    binder(this, { internal: ["handleClick"] });
  }

  handleClick() {}

  handleChange() {}
}

Bind only those that are not external methods.

import binder from "class-methods-binder";

class Example {
  constructor() {
    binder(this, { external: ["handleClick"] });
  }

  handleClick() {}

  handleChange() {}
}
1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago