sky-bind

1.0.3 • Public • Published

sky-bind

Bind all your class methods with one line.

Install

npm install sky-bind

Usage

import { bindAll } from "sky-bind";

class A {
  name = "A";

  constructor() {
    bindAll(this); // done, all your class methods have bind this already.
    // this.onclick = this.onclick.bind(this); // that's no need here
  }

  onclick() {
    console.log("hello", this.name); // this will always pointer to this A instance
  }
}

Package Sidebar

Install

npm i sky-bind

Weekly Downloads

17

Version

1.0.3

License

none

Unpacked Size

1.9 kB

Total Files

3

Last publish

Collaborators

  • sky0014