3 ms·
This is a bit overly critical. The implicit parentheses are optional, so if it's confusing or ambiguous you should just use parentheses. func 5, { e
by rzimmerman 13y ago
This is a bit overly critical. The implicit parentheses are optional, so if it's confusing or ambiguous you should just use parentheses.
func 5, {
event: -> 45,
val: 10}
Is reasonable but
func 5, {
event: (e) ->
if e.something
36
else
45,
val: 10}
Really ought to be split up for readability no matter what programming language you use. And besides, the only issue is the extra comma causes it not to compile.
To be fair, the `->` vs `=>` (which `this` is `this`?) for class members is confusing. I'd almost prefer class members didn't give you the option and defaulted to `=>`.
The "variable capture" section is overblown, though. You're a lot less likely to run into this issue than the classic JavaScript "I forgot `var` and now my variable is global.
My biggest complaint is actually the implicit returns. Sometimes I forget a return statement but it works anyway because of this feature. Then I come back later and modify the function slightly only to spend a bunch of time figuring out why it's returning `undefined`.
- jkrems 13y agoIf you write JavaScript in strict mode the probability of incidentally declaring something as global is pretty much zero. Those mistakes can also be properly linted and warned against - which is not possible for CoffeeScript's implicit declarations. And at least I had real-life situations where CoffeeScript's scoping broke code in very subtly ways.