W3C home > Mailing lists > Public > www-dom@w3.org > October to December 2011

EventTarget.on

From: Jake Verbaten <raynos2@gmail.com>
Date: Mon, 21 Nov 2011 15:13:02 +0000
Message-ID: <CAMCMjp2HmFT_1O+p1xWN904w_4qpnNizavCgV9iTM+KNqJK2hg@mail.gmail.com>
To: www-dom@w3.org
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 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:14:08 GMT