2015/04/05

[CoffeeScript]if orのsyntax sugar

JavaScriptで次のようなケースがよくあります。

if(hoge == "1" || hoge == "2" || hoge == "3"){
 
}
これ、Coffeescriptの場合、次のように簡単に書くことができます。
foo = 'hello'
#true
if foo in ['hello','goodbye','see again']
  console.log "test"

foo = 'hey'
#false
if foo in ['hello','goodbye','see again']
  console.log "test"

0 コメント:

コメントを投稿