Functions that Implement the EventListener Interface (DOM Level 3 Events)

Hi, I recently ran into an issue testing some code across different browsers that caused me to take a look at the specification for the addEventListener() method on the EventTarget interface. In my particular case, I had a constructor function that also implemented the EventListener interface (that is, it had a function named "handleEvent" as a property). The spec is extremely unclear on what should happen in this case. At http://www.w3.org/TR/DOM-Level-3-Events/#events-EventTarget-addEventListener, it says:

> The listener parameter must be an object which implements the EventListener interface, such as a reference to a .
> 
> The listener parameter must be either an object that implements the EventListener interface, or a function. If listener is a function then it must be used as the callback for the event; otherwise, if listener implements EventTarget, then its handleEvent method must be used as the callback.
> 
> The listener parameter takes an object defined by the author which implements the EventListener interface and contains the method to be called when the event occurs.
> 

The first paragraph is clearly incomplete, the second seems to indicate that, in my case, the constructor function should be called, and the third is ambiguous at best and contradicts the second at worst.

For what it's worth, I think WebKit's current behavior is preferable (in my case, myConstructor.handleEvent() would have been called instead of myConstructor()), though it is different from how Firefox, Opera, and Chrome behave (myConstructor() would be called instead of myConstructor.handleEvent()). At the very least, it would be nice the get the wording here more clear.

There is also an open bug on WebKit about this (http://webkit.org/b/62518), but, as I noted above, I vastly prefer the current behavior and would love not to have to commit it :)

Thanks,

Rob Brackett

Received on Tuesday, 14 June 2011 00:29:51 UTC