class-methods-binder

1.0.3 • Public • Published

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() {}
}

Readme

Keywords

Package Sidebar

Install

npm i class-methods-binder

Weekly Downloads

1

Version

1.0.3

License

Apache-2.0

Unpacked Size

114 kB

Total Files

9

Last publish

Collaborators

  • aykutkardas