Re: [WebIDL] Simplify callbacks

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