Skip to content

sky0014/bind

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

bind

Bind all your class methods with one line.

Install

npm install @sky0014/bind

Usage

import { bindAll } from "@sky0014/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
  }
}

About

Bind all your class methods with one line.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published