Re: ECMAScript binding for EventListener

--- Jim Ley <jim@jibbering.com> wrote:
> It's not a lot of different, it's still reasonably
> neat.   I don't see
> the point in making things more complicated for no
> reason, keep the
> implementation simple, and small, and fast and only
> add features that are
> truly of value, I'm still unsure as to exactly where
> this would be of
> particular value - are there any non trivial
> examples?

My purpose was for capturing click events, and
rerouting double and triple clicks.  The idea was to
capture all clicks to a generic method of a class for
handling events, and then reroute the event based on
the detail property.  If you want to do this is an
object-oriented manner, you must do something like
Jeff's suggestion, or add an attribute to the element
the event is fired upon which has a reference to
"this" for the object itself.  For the latter,
something like:

function EventHandlerClass(el)
{
   this.el = element
   this.el.backPointer = this
}

function addEventListeners()
{
  
this.el.addEventHandler("click",this.singleClick,false);
}
EventHandlerClass.prototype.addEventListeners =
addEventListeners;

function singleClick(e)
{
   if(e.detail==2) this.backPointer.doubleClick(e);
  //
}
EventHandlerClass.prototype.singleClick = singleClick;

function doubleClick(e)
{
   //
}
EventHandlerClass.prototype.doubleClick = doubleClick;

The current behavior seems to have redundancy between
"this" and the first argument passed in an event. 
What benefit does "this" provide that you couldn't get
just as easily from a property or method on the event
argument?

-Dylan Schiemann


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

Received on Tuesday, 10 July 2001 11:03:41 UTC