Hacker News new | ask | show | jobs
by jaggederest 5020 days ago
The situation where it matters is with a trailing function argument, i.e.

    $ ->
      # do something on document ready
      $.ajax('path', options, (data) ->
        # do something with the results
Instead of

    $(->
      # do something on document ready
      $.ajax('path', options, (data) ->
        # do something with the data
      )
    )
Those trailing parens are ugly, and they're very common if you do event-oriented javascript via closures.
1 comments

This is why our codebase uses paren-less calls when there is a trailing function argument, but uses parens in all other cases. It makes the code far, far more readable.
I agree, but I think making it a language restriction would be very odd. Coming from ruby, I also tend to think that this might be a nice way to do it, for things taking a final optional callback argument.

    $.ajax('path', options) (data) ->
      # do something with the data
But it does read less clearly, unfortunately.