- From: David Flanagan <dflanagan@mozilla.com>
- Date: Thu, 10 Nov 2011 10:14:07 -0800
- To: public-script-coord@w3.org
- Message-ID: <4EBC146F.6090207@mozilla.com>
On 11/10/11 12:06 AM, Jonas Sicking wrote: > 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 > My understanding of Anne's original proposal is that the method name part was secondary. Primarily, it was a proposal to simplify WebIDL so that spec authors wouldn't have to define useless single-method interfaces like EventListener, and decorate them with [Callback]. And also decorate them with [NoInterfaceObject] or clutter up the global namespace like EventListener does. In order to achieve that simplification, Anne suggested standardizing handleEvent() as the method name. No one likes that, but the basic idea is still an interesting one, if a suitable WebIDL syntax can be devised. Some sort of WebIDL function type that is parameterized by (or annotated with) an allowed method name and also argument types if those are necessary. So then we could declare methods like addEventListener without an EventListener interface: void addEventListener(DOMString type, [MethodName=handleEvent] function<Event>? listener, optional boolean capture); I'm not convinced that a suitably non-ugly syntax can be devised, however, and I don't know what Cameron thinks about this sort of wholesale alteration to WebIDL syntax. David
Received on Thursday, 10 November 2011 18:14:41 UTC