Ternary operation in CoffeeScript

前端 未结 7 1659
生来不讨喜
生来不讨喜 2020-12-04 06:56

I need to set value to a that depends on a condition.

What is the shortest way to do this with CoffeeScript?

E.g. this is how I\'d do it in Java

7条回答
  •  清歌不尽
    2020-12-04 07:22

    Multiline version (e.g. if you need to add comment after each line):

    a = if b # a depends on b
    then 5   # b is true 
    else 10  # b is false
    

提交回复
热议问题