autobindthis
Binds methods to their class instance automagically
Install
$ npm install autobindthis
Usage
const autobind = ; { thisname = name; ; } { return ` comes closer!`; } const bat = 'Quasel'; // Reference the method off the class instanceconst ultrasonic = batultrasonic; // 'this' still refers to the class instance;//=> 'Quasel comes closer!' // Without `autobind(this)`, the above would have resulted in;//=> Error: Cannot read property 'name' of undefined
API
autobind(self, [options])
Binds methods in self
to their class instance.
self
Type: Object
Object with methods to bind.
options
Type: Object
exclude
Type: Array<string>
Given methods are excluded from binding
autobind.react(self, [options])
Same as autobind
, uses predefined set of method names to exclude the default React component methods.
Component { superprops; autobind; } // …
License
MIT