3 ms·
I'm not sure where you got that idea -- it's not at all true. "or=" is the same as "||=", and means: Assign the variable on the left to the value on the right
by jashkenas 15y ago
I'm not sure where you got that idea -- it's not at all true.
"or=" is the same as "||=", and means: Assign the variable on the left to the value on the right if the variable is falsy.
"?=" means: Assign the variable on the left to the value on the right if the variable does not yet exist (ie. is either "null" or "undefined").
Two different things, both useful.
- axiak 15y agoSince ?= looks so familiar, any chance of an elvis or defined-or operator in coffeescript? if a? then a else 0 becomes either a ?: 0 (if you like groovy) or a // 0 (if you like perl)
- stoodder 15y agoGotcha, thanks for the correction! I've removed my post. Could you clarify if or= still exists? I was reading the change log for 1.3.1 and I think I may have interpreted this line incorrectly "Conditional assignment of previously undefined variables a or= b is now considered a syntax error.". Thanks!
- natep 15y agoMy interpretation of your quote is that the feature is there, but if the LHS is undefined, then the error is caught by the compiler, rather than at run-time (what is the falsity of an undefined value?)
- stoodder 15y agoYea, you're correct. This has been one of those "duh" moments. Thanks for the reply!