npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript.Learn more »

autobind

1.0.3 • Public • Published

autobind

autobind decorator

Usage

Auto bind method
class A {
  constructor() {
    this.x = 123;
  }
  @autobind
  f() {
    return this.x;
  }
  g() {
    return this.x;
  }
}
 
var a = new A();
 
a.f.call({ x: 456 }) === 123; // true
a.g.call({ x: 456 }) === 456; // true
Auto bind class methods
@autobind
class A {
  constructor() {
    this.x = 123;
  }
  f() {
    return this.x;
  }
  g() {
    return this.x;
  }
}
 
var a = new A();
 
a.f.call({ x: 456 }) === 123; // true
a.g.call({ x: 456 }) === 123; // true

Keywords

none

install

npm i autobind

Downloadsweekly downloads

974

version

1.0.3

license

MIT

last publish

collaborators

  • avatar
Report a vulnerability