EventTarget.on

addEventListener is long and verbose. Could we have `on` as a synonym for
addEventListener ?

 - node.js has it's own EventEmitter object that's similar to an
EventTarget and it has an
`on`<http://nodejs.org/docs/v0.6.2/api/events.html#emitter.on> method
which is just a synonym for their addListener method.
 - jQuery also has it's own event API and has an
`on`<http://api.jquery.com/on/> which
is a synonym for their bind method (ignore the fact it's overloaded to do
other stuff).
 - YUI3 has an `on`<http://yuilibrary.com/yui/docs/api/classes/EventTarget.html#method_on>
 method
 - Element.on<EventName>, we already have a large range of properties
called onclick, onchange, etc. Thus adding the on method would be familiar.
e.onclick = cb and e.on("click", cb) are similar enough to be readable

on is a short term that is known and familiar in the javascript community
and I'd reduce the verbosity of the DOM, which is one of the top complaints.

This ties in with the improving the DOM thread which suggest a set of less
verbose shorthands for element manipulation.

IDL wise it would just be

    void on(DOMString type, EventListener? listener, optional boolean
capture);

    When the on(type, listener, capture) method is invoked run the
addEventListener steps.

Received on Monday, 21 November 2011 15:13:34 UTC