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

Re: Functions that Implement the EventListener Interface (DOM Level 3 Events)

From: Jonas Sicking <jonas@sicking.cc>
Date: Thu, 23 Jun 2011 12:13:38 -0700
Message-ID: <BANLkTi=+z-VJy=Uf8qOTCiiAWnvYbDFuMA@mail.gmail.com>
To: "Olli@pettay.fi" <Olli@pettay.fi>, Rob Brackett <rbrackett@apple.com>, "www-dom@w3.org" <www-dom@w3.org>, Jacob Rossi <jrossi@microsoft.com>
On Wednesday, June 22, 2011, Cameron McCormack <cam@mcc.id.au> wrote:
> Olli Pettay:
>> D3E could be clarified, but seems like this is anyway defined in WebIDL.
>
> I agree, it is defined in Web IDL.  I remember changing the order in
> which the handler is checked for (between the property and the function
> itself) some time ago, due to feedback.
>
> Here is a test:
> http://people.mozilla.org/~cmccormack/tests/eventlistener-property.html
>
> The first sub-test is doing
>
>   addEventListener(…, { handleEvent: function() { … } }, …);
>
> and the second sub-test is doing
>
>   function b() { … }
>   b.handleEvent = function() { … };
>   addEventListener(…, b, …);
>
> The results are that every browser invokes the handler in the first
> sub-test, and for the second sub-test, Firefox/Chrome/Opera/IE use the
> function object itself, while Safari uses the property.
>
> I agree that preferring the property makes some sense to me (especially
> if you consider JS implementing an interface with more than one
> operation on it), but the change was made to match the implementations.

It is also more performant to execute the function rather than the
property since that way you cam do decide which to use at registration
time, rather than each time the callback is called.

/ Jonas
Received on Thursday, 23 June 2011 19:14:07 GMT

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