Forces class methods to be bound to instances. There are plenty of libraries to do this already, but this one is my one. Also I wrote tests.
Preconfigured for React, i.e. ignores render()
and component...()
methods.
Via npm:
$ npm install --save yaab
import bindMethods from 'yaab';
class TestClass {
constructor() {
this.property = 'value';
bindMethods(this);
}
method() {
return this.property;
}
}
const instance = new TestClass();
const { method } = instance;
console.log(method()); // => 'value'
Binds all methods on the object to itself.
Object with methods to be bound. Typically a "this" at the end of a constructor.
Array of method names to ignore.