W3C home > Mailing lists > Public > public-script-coord@w3.org > October to December 2011

Re: [WebIDL] Simplify callbacks

From: Jonas Sicking <jonas@sicking.cc>
Date: Thu, 10 Nov 2011 00:06:49 -0800
Message-ID: <CA+c2ei9Zt1FEZ6ETMA4vZdgVJL2CS-XQKhGyk4A15_GHN-dHeg@mail.gmail.com>
To: Anne van Kesteren <annevk@opera.com>
Cc: "public-script-coord@w3.org" <public-script-coord@w3.org>
On Tue, Nov 8, 2011 at 6:47 AM, Anne van Kesteren <annevk@opera.com> wrote:
> It seems that all callbacks use handleEvent() and we cannot change that at
> this point I think. We should simplify callback syntax to a) make IDL easier
> to read and b) ensure consistency throughout the platform.
>
> addEventListener(DOMString type, Callback(Event)? listener, optional boolean
> capture)

As others have pointed out, I think this is entirely the wrong direction to go.

The whole point of being able to pass in an object and have a function
called on that object is to allow the page to have an object which
registers as a listener to several callbacks and reacts to all of them
appropriately.

If you are just listening to a single callback you might as well use a
function with a closure.

However if all callbacks use the same function name, then we've lost
all advantages of using an object with member functions since all
callbacks would go to the same member function.

Instead we should encourage callbacks to use descriptive names for the
callback function so that it makes sense to have a observer object
which listens to multiple callbacks using separate functions.

/ Jonas
Received on Thursday, 10 November 2011 08:07:56 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 8 May 2013 19:30:04 UTC