- From: Dylan Schiemann <dylans@yahoo.com>
- Date: Thu, 14 Jun 2001 19:07:19 -0700 (PDT)
- To: Johnny Stenback <jst@netscape.com>, David Flanagan <david@oreilly.com>
- Cc: www-dom@w3.org
--- Johnny Stenback <jst@netscape.com> wrote:
>
>
> David Flanagan wrote:
>
> > In the Level 2 DOM, the ECMAScript binding for the
> EventListener
> > interface is simply a function reference.
> >
> > While this is very convenient for JavaScript
> programmers, it sacrifices
> > the power that comes with treating EventListener
> as a true object.
> > Specifically, the current binding allows us to
> register only functions
> > as event handlers, and does not allow us to
> register object methods as
> > handlers. (Mozilla currently invokes any event
> handler function you
> > register as a method of the event target.)
> >
> > I'd like to propose that the next edition of the
> specification broaden
> > the ECMAScript binding so that EventListener may
> be either a function or
> > an object. If an object o is registered, it must
> have a property named
> > handleEvent that contains a function reference.
> When the appropriate
> > event occurs, this function is invoked _as a
> method of the object o_.
> >
> > As a trivial example, I ought to be able to write
> code like this:
> >
> > element.addEventListener("click",
> > {
> > message: "Hello world",
> > handleEvent: function(e) {
> alert(this.message); }
> > },
> > false);
> >
> > Anyone have thoughts about this?
> >
>
>
> For the record, this already works in recent
> versions of mozilla (and
> Netscape 6.1 beta).
>
Yes, it actually does. Though something like:
function EventCaptureClass()
{
}
function addEventListeners(element)
{
element.addEventListener("click",this.singleClick,false);
}
EventCaptureClass.prototype.addEventListeners =
addEventListeners;
function singleClick(e)
{
alert(this); // this = element, not the instance of
the singleClick method.
}
EventCaptureClass.prototype.singleClick = singleClick;
would be greatly served by David's suggestion.
-Dylan Schiemann
http://www.sitepen.com/
http://www.dylanschiemann.com
__________________________________________________
Do You Yahoo!?
Spot the hottest trends in music, movies, and more.
http://buzz.yahoo.com/
Received on Thursday, 14 June 2001 22:07:20 UTC