Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I got to use bind for a class based event handler, using arrows would bind this to the wrong context.. but maybe I'm doing it wrong.


I've used this syntax which auto-binds this, worked for me

  class Thing {
    method1 = () => {}
    method2 = () => {
      something.addEventListener('click', this.method1);
    }
  }


Fun trick. A bit tangled though




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: