Re: Clarify addEventListener/removeEventListener listener argument type [WebApps-ISSUE-174]

On 12/23/10, Doug Schepers <schepers@w3.org> wrote:
> Hi, Sergey-
>
> I have clarified in the DOM3 Events spec [1] that the listener parameter
> can be an inline function object.
>
> Please let us know whether or not this satisfies your issue.
>
> [1] http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html/DOM3-Events.html
>
You have there:

| 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.
|
| Note: The listener may be a reference to a function object
| or an inline function object literal.
|
The listener parameter does not *take* an object; it is either an
object that implements EventTarget or a function. By "the method," I
believe the reader is to assume `handleEvent`. Don't make the reader
assume things. "Defined by the author" is superfluous.

"inline function object literal" is made up terminology.

| The listener parameter must be either an object that implements
| EventListener or a Function. If `listener` is a function then
| it is used as the callback for the event. Otherwise, if
| listener implements EventTarget, then its `handleEvent` method
| is used as the callback.
|
| Otherwise, the outcome is unspecified.

Use that for now.

IMO when `listener` is neither a function nor an object that
implements EventTarget, an error should be thrown (fail fast).

However, examples of that in IE9 beta, Firefox 3.6, Safari 4 don't
agree with when I think the error should fire.

el.addEventListener("click", null, false);
el.addEventListener("click", {}, false);
el.addEventListener("click", {handleEvent: null}, false);
-- 
Garrett

Received on Friday, 24 December 2010 06:42:09 UTC