Expression closures - use-cases for shortcut lambda syntax (blocks)

Jeff Walden jwalden at MIT.EDU
Fri Mar 16 23:51:44 PDT 2007


Neil Mix wrote:
> addLoadEvent() {
>      var elems = getElementsByTagAndClassName("A", "view-source");
>      var page = "rounded_corners/";
>      for (var i = 0; i < elems.length; i++) {
>          var elem = elems[i];
>          var href = elem.href.split(/\//).pop();
>          elem.target = "_blank";
>          elem.href = "../view-source/view-source.html#" + page + href;
>      }
> }

This syntax is whitespace-significant; the presence or absence of a line terminator between the closing parenthesis after the function name and the opening brace affects behavior.  If a line terminator occurs, semicolon insertion transforms it into a method call of no arguments and a block statement.  If a line terminator doesn't occur, your behavior works (in an ES4 implementation, that is).  The existing no-line-terminator uses are annoying enough, particularly in the case when I want to return an object from a method, and I'd rather see as few new instances (which don't mimic the existing ones) as possible, personally.

Jeff

-- 
Rediscover the Web!
http://snurl.com/get_firefox

Reclaim Your Inbox!
http://snurl.com/get_thunderbird



More information about the Es4-discuss mailing list