delegatejs

1.1.2 • Public • Published

DelegateJS

performant object scope function [event] delegation like function.bind or jquery.proxy

Install

npm install delegatejs

Usage

 
const delegate = require('delegatejs');
 
class Test {
    
  constructor() {
    window.addEventListener('resize', delegate(this, this.onResize), false);
  }
  
  onResize(e) {
    console.log(this, e);
  }
}
 

if you also need to remove your listener (what you always should do in statefull apps) you can du so:

 
const delegate = require('delegatejs');
 
class Test {
    
  constructor() {
    this.onResize = delegate(this, this.onResize);
    window.addEventListener('resize', this.onResize , false);
  }
  
  onResize(e) {
    console.log(this, e);
  }
 
  removeResizeListener(){
    window.removeEventListener('resize', this.onResize);
  }
}
 

Package Sidebar

Install

npm i delegatejs

Weekly Downloads

171

Version

1.1.2

License

MIT

Last publish

Collaborators

  • soenkekluth