W3C home > Mailing lists > Public > www-dom@w3.org > April to June 2001

Re: ECMAScript binding for EventListener

From: Jeff Yates <PBWiz@mail.pbwizard.com>
Date: Fri, 15 Jun 2001 01:59:51 -0400
Message-Id: <200106150159.AA405799082@mail.pbwizard.com>
To: David Flanagan <david@oreilly.com>, <jst@netscape.com> (Johnny Stenback)
CC: <www-dom@w3.org>
This is not needed.  It can already be implemented (in a modified mannor) as follows:

function objectEventHandler( object, methodName, element){
    element.addEventListener( "click", function(evt){
            object[methodName](evt);
        },
        false );
}


>From this you can see that the object's method is called.  Every time objectEventHandler is called object, method and element can be different.  There is no need for what you are asking for.

This is very simular for how I implemented the onreadystatechange event handler for M$'s XMLDOMDocument since it does not have a this reference.

Jeff Yates.
http://www.pbwizard.com




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?
> 


--
Jeff Yates
e-mail:    PBWiz@PBWizard.com
Homepage:  http://www.PBWizard.com

--
Received on Friday, 15 June 2001 02:00:03 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:13:48 GMT