Live data from Hacker News

Brief Video: Rewriting JavaScript into CoffeeScript

ryanflorence.com

1–10 of 27 posts

Re: Brief Video: Rewriting JavaScript into CoffeeScript

#6
post #5

[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.

Re: Brief Video: Rewriting JavaScript into CoffeeScript

#7
post #5

[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.

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)

Re: Brief Video: Rewriting JavaScript into CoffeeScript

#9
post #7

Earlier 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)

You've already got that. To cover my bases... The existential operator can be used infix:

  result = a ? 0
Or postfix (does "result" exist?)

  result?
Or to conditionally assign, as we've seen above:

  result ?= a
Post reply on HN