CoffeeScript has two forms : switch
switch expr
when expr1
result1
...
else
default_result
and
switch
when expr1
result1
...
else
default_result
Both forms are, of course, expressions, so you can say:
x = switch expr
when val then result
...
and
x = switch
when expr then result
...
switch exprsimilar to JavaScript switch: you compare the result exprwith each expression whenand execute whenfrom ==to expr. This form switchis the same as:
if(expr == expr1)
result1
else if(expr == expr2)
result2
...
else
default_result
switch ... when when expr, expr , :
if(expr1)
result1
else if(expr2)
result2
...
else
default_result
, , switch .
, - :
arr = "coffee_script"
switch arr
when 'coffee_script'
item.type = arr
...