W3C home > Mailing lists > Public > public-webapps@w3.org > April to June 2009

addEventListener naming

From: Alex Russell <slightlyoff@google.com>
Date: Fri, 24 Apr 2009 14:31:52 -0700
Message-ID: <6fc58d0d0904241431n290e8166m1e126cc02e735564@mail.gmail.com>
To: public-webapps@w3.org
>From this thread on whatwg:

    http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2009-April/019379.html

and per Hixie's request that I re-direct this particular discussion here:

    http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2009-April/019381.html

The DOM function "addEventListener" is probably too long. It should,
instead, be named something much shorter owing to the amount of
exercise it receives. Further, it should default the last parameter to
be "false" (non-capture-phase). This call:

    node.addEventListener("click", function(e) { /* ... */ }, false);

Should be able to be written as (e.g.):

    node.listen("click", function(e) { /* ... */ });

Similarly, "removeEventListener" should be aliased as "unlisten". As a
further help, the common-case operation of listening-for-a-single-call
is currently written as:

    var h = function(e) {
        /* .... */
        node.removeEventListener(h);
    };
    node.addEventListener("click", h);

And given how common this operation it, it should probably have an alias:

    node.listenOnce("click", function(e) { /* ... */ });

Regards
Received on Friday, 24 April 2009 21:32:32 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:31 GMT