Better way to maintain this reference on event listener functions

Mark Kennedy mkay581 at
Mon May 9 17:20:45 UTC 2016

Thanks, Bob. Unless I'm missing something, this code you wrote will not
remove the event listener when `unlisten` is called. Check out [this
answer]( on stackoverflow.

function listen(element, type, handler) {
  element.addEventListener(type, handler);
  return function() {
    element.removeEventListener(type, handler);

var unlisten = listen(myElement, 'click', e => this.handler(e));



Sent while riding a hoverboard... :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list