1.0.3 • Published 6 years ago
class-methods-binder v1.0.3
Class-Methods-Binder
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() {}
}