Re: ECMAScript binding for EventListener

--- Jim Ley <jim@e-media.co.uk> wrote:

> My problem with it, is the unnecessaryness it takes
> a function, if you
> want it to be a function of an object, that doesn't
> matter, remember all
> functions are functions of the global object in
> ECMAScript
>
> I don't really see the functional difference between
>
> element.addEventListener("click",
> window.someEventHandler, false);
> and
> element.addEventListener("click",
> customObject.someEventHandler,false);
>
> The proposal is for:
>
element.addEventListener("click",customObject,false);

There is a big difference between simply registering a
function as an event handler versus registering an
object method as an event handler.

> Which I don't really see as giving anything over and
> above the second
> example above, and I do not think adding things of
> little real value
> really has a place in the recommendation, such an
> extension to the DOM
> wouldn't cause any problems as I could see so
> implementors could be free
> to add such behaviour if they wish - but to force
> them to I see little
> sense - it'll just increase development and testing
> times leading to less
> compliant DOMs.

It requires the method which adds the event listener
to have an explicit reference to its instance.

The two options for this that I see are:
1) the object must know its identity. You must pass in
a reference to the instance of the object.

2) give the node on which the event is called a
pointer to the object.

It really breaks the spirit of o-o by having to resort
to one of these two options.

FWIW, that other browser company does make "this"
refer to the customObject, not the node on which the
event was fired. (not that following their
implementation is any meaningful reason)

> > The current behavior seems to have redundancy
> between
> > "this" and the first argument passed in an event.
>
> Not if the this isn't the DOM object in question,
> the examples above give
> different "this"'s to the the first argument.

I'm not sure I understand what you are saying here...
probably too many "this"... but don't the first and
second examples you gave both have "this" equal to the
element on which the event was fired when in the
context of the event handler function?

-Dylan Schiemann 


__________________________________________________
Do You Yahoo!?
Spot the hottest trends in music, movies, and more.
http://buzz.yahoo.com/

Received on Friday, 15 June 2001 12:30:33 UTC