3 ms·
The situation where it matters is with a trailing function argument, i.e. $ -> # do something on document ready $.ajax('path', options, (data)
by jaggederest 14y 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.
- stickfigure 14y agoThis 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.
- jaggederest 14y agoI 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.