Binds this to all methods of your class
Your mess stuff:
constructor() {
// .......
this.method1 = this.method1.bind(this);
this.method2 = this.method2.bind(this);
this.method3 = this.method3.bind(this);
this.method4 = this.method4.bind(this);
// .......
}Now, only one line to clear your mess.
constructor() {
// .......
bindMethods(this);
// .......
}Install
npm i @sontx/bindthisor
yarn add @sontx/bindthisIn your code
import bindMethods from "bindthis";
class MyClass {
constructor() {
// ..............
bindMethods(this);
// ..............
}
// ..............
method1() {}
method2() {}
}