Description
Inspired by this discussion, where @jashkenas suggested I file a ticket for it.
Synopsis
Before:
$('some_selector').click (e) ->
#... handler code...
After:
$ 'some_selector' .. click (e) ->
#... handler code...
Details
Add a new syntax for calling methods with low precedence, suitable for chaining. In the example above I use ..
, but that's just a suggestion off the top of my head; it could be anything.
Why?
As I'm finally getting a chance to use CoffeeScript for real, I've been immediately struck by two things: the language and conventions strive to avoid extra parenthesis (yay!) but in many common cases that's not completely possible (boo!). As a result, I see a lot of code like the "before" example which mixes paren and paren-free calling. Since I strive for code in which "same things look the same", this was a bit jarring. When I first saw the code above it signaled to me that there was something "special" about the call to jQuery's $()
method, since it required parens and the call to .click
did not. As it turns out the only thing special about is was that it was not at the end of the line.
The suggested change would enable even more put-the-top-down-and-let-the-breeze-blow-through-your-hair paren-free coding, which I think would be a Good Thing.