jashkenas / coffeescript

Unfancy JavaScript
https://coffeescript.org/
MIT License
16.5k stars 1.99k forks source link

simplify negated existence compilation #1215

Closed michaelficarra closed 10 years ago

michaelficarra commented 13 years ago

A minor optimization:

dvv commented 13 years ago

I believe to (typeof a == "undefined" || a == null) and (a.b == null), notice the braces

michaelficarra commented 13 years ago

@dvv: Depending on the situation, possibly. But the compiler will handle that for us.

jrus commented 13 years ago

Yes, I was a bit puzzled that these two behave differently:

foo unless a?
foo if not a?

Namely:

if (typeof a == "undefined" || a === null) {
  foo;
}
if (!(typeof a != "undefined" && a !== null)) {
  foo;
}
michaelficarra commented 13 years ago

@jrus: They don't behave differently, but they do (unfortunately) compile differently.

jrus commented 13 years ago

Yeah, I meant the compiler behaves differently, not that the output behaves differently. Silly ambiguous English. :)

vendethiel commented 10 years ago

Seems to work that way.