Elegie said:
Richard said:
[4] Instead of passing the handler directly, pass some object
implementing the EventListener interface.
That is very risky in javascript. The W3C ECMAScript bindings
for the EventListener interface effectively say that any
_function_ is an EventListener. The fact that some browsers also
allow an object that resembles a Java EventListener to be used
(and object with specific methods) is a non-specified extension.
Richard, the specification would then be poorly worded.
That may be true, though maybe only to the extent that trying to
misinterpret it remains too practical.
Previous versions were certainly less misleadingly worded, for example
the ECMAScript Binding for the November 2000 version of DOM Level 2
events describes EventListener as:-
| Object EventListener
| This is an ECMAScript function reference. This method has no
| return value. The parameter is a Event object.
and - EventTarget - as:-
| Object EventTarget
| The EventTarget object has the following methods:
| addEventListener(type, listener, useCapture)
| This method has no return value.
| The type parameter is of type String.
| The listener parameter is a EventListener object.
| The useCapture parameter is of type Boolean.
| removeEventListener(type, listener, useCapture)
| This method has no return value.
| The type parameter is of type String.
| The listener parameter is a EventListener object.
| The useCapture parameter is of type Boolean.
| dispatchEvent(evt)
| This method returns a Boolean.
| The evt parameter is a Event object.
| This method can raise a EventException object.
The version you cite has changed the wording of the bindings document,
but does not appear to have changed its intended meaning.
The bindings page states the existence of one
"EventListener Function",
And that is the _only_ definition of what an EventListener is in an
ECMAScript implementation: it is a function (that accepts an event
object as an argument and has no (explicit) return value).
how could you tell it does not refer to the handleEvent
function?
Compare the definition of EventListener with the definitions of
interfaces that include methods and properties. If EventListener was
intended to be anything but a function object then the bindings could
easily have expressed that.
All the more that the bindings page mentions, in the EventTarget
description, "objects that implements the EventListener interface",
and not "EventListener Functions".
Maybe not the best of expressions, but a function is an object and
implementing the " EventListener interface" involves being a function
(that accepts an event object as an argument and has no (explicit)
return value).
<URL:
http://www.w3.org/TR/2006/WD-DOM-Level-3-Events-20060413/ecma-scrip
t-binding.html>
To me it would seem as if the direct use of the function would
_not_ be standard, but rather some implicitly accepted exception
due to historical reasons (for instance as the consequence of
assigning functions to regular HTML event attributes).
If that were the case I would expect to see the definition of
EventListener resemble EventTarget or Event, and explicitly state that
the interface has a method and the arguments and return values for that
method.
Of course, I would not be encouraging the use of the
EventListener interface in ECMAScript programs
If the EventListener interface is just a function object they why not?
By the way I do not have lots of browsers on this station,
if you would happen to know about some browsers supporting
the DOM Event Model and not allowing the use of EventListener
as described, please let me know.
The last time we discussed this subject here only Mozilla/Gecko browser
supported a Java-style version of EventListener. It looks like Opera
have seen it as expedient to add such support, but I don't know whether
Konqueror, Safari, NetFront, IceBrowser, etc. will have done so.
Richard.