Skip to content

sontx/bindthis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bindthis

npm npm Travis (.org)

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);
  // .......
}

Usage

Install

npm i @sontx/bindthis

or

yarn add @sontx/bindthis

In your code

import bindMethods from "bindthis";

class MyClass {
  constructor() {
    // ..............
    bindMethods(this);
    // ..............
  }
  // ..............
  method1() {}
  method2() {}
}

About

Binds "this" to all methods of your javascript class

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published