Brief Video: Rewriting JavaScript into CoffeeScript
ryanflorence.com
Brief Video: Rewriting JavaScript into CoffeeScript
1–10 of 27 posts
Re: Brief Video: Rewriting JavaScript into CoffeeScript
#2Re: Brief Video: Rewriting JavaScript into CoffeeScript
#3Re: Brief Video: Rewriting JavaScript into CoffeeScript
#4But... why?
Re: Brief Video: Rewriting JavaScript into CoffeeScript
#5Re: Brief Video: Rewriting JavaScript into CoffeeScript
#6[deleted]
"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.
Re: Brief Video: Rewriting JavaScript into CoffeeScript
#7[deleted]
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.
if a? then a else 0
becomes either a ?: 0 (if you like groovy)
or a // 0 (if you like perl)Re: Brief Video: Rewriting JavaScript into CoffeeScript
#8Re: Brief Video: Rewriting JavaScript into CoffeeScript
#9Earlier quoted context omitted.
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.
Since ?= 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)
result = a ? 0
Or postfix (does "result" exist?) result?
Or to conditionally assign, as we've seen above: result ?= aRe: Brief Video: Rewriting JavaScript into CoffeeScript
#10But... why?