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

Re: [WebIDL] Simplify callbacks

From: Ian Hickson <ian@hixie.ch>
Date: Thu, 15 Dec 2011 00:35:40 +0000 (UTC)
To: Cameron McCormack <cam@mcc.id.au>
cc: "public-script-coord@w3.org" <public-script-coord@w3.org>, Anne van Kesteren <annevk@opera.com>
Message-ID: <Pine.LNX.4.64.1112150030530.26122@ps20323.dreamhostps.com>
On Wed, 14 Dec 2011, Cameron McCormack wrote:
> Either we embrace object-with-property for all APIs that take callbacks, 
> giving them meaningful method names, or we decide that all future APIs 
> take only Functions.  Allowing object-with-property for new APIs but 
> using handleEvent for them all seems like a sucky compromise to me.

I think that the sucky situation would be to have lots of places that take 
callbacks, but have to keep looking up what the heck the function is 
called in order to use the object form.

Consider an API that you can use whenever a callback is needed to track 
the number of calls to the callback. If every callback uses a different 
function name, you'd have to tell this API what the context of the 
callback was instead of just being able to use it blindly. Consider what 
it would take to change the implementation of such an API from using 
closures to using an object to store data. Suddenly, every call site would 
need to be updated to provide the callback method name.

Don't think of "handleEvent" as meaning "handle a DOM Event object". Think 
of it as "handle an event", the event being "the callback was invoked". 
There's plenty of precedent for callbacks being called "HandleEvent".

Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'
Received on Thursday, 15 December 2011 00:36:11 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:14:05 UTC