delegate.js icon indicating copy to clipboard operation
delegate.js copied to clipboard

Doesn't support EventListener interface

Open WickyNilliams opened this issue 10 years ago • 1 comments

An object that implements EventListener interface (https://developer.mozilla.org/en-US/docs/Web/API/EventListener) has a handleEvent method. e.g.:

var obj = {
  log : function(e) {
    console.log("event", e.type, "happened on", e.target);
  },
  handleEvent : function(e) { 
     this.log(e); 
  }
};

Notice that the this value in handleEvent is bound to the object itself. As obj implements the EventListener interface, it can be registered directly as an event listener:

document.addEventListener("click", obj, false);

It would be great if the EventListener interface was respected by delegate.js and worked as one would expect:

delegate(body).on("click", ".some-selector", obj);

WickyNilliams avatar Jan 27 '14 12:01 WickyNilliams

Sounds good.

necolas avatar Feb 07 '14 02:02 necolas