是否有任何coffeescript特定的技巧,使这看起来更整洁:
index = (->
if segment == 'index'
return 0
else if segment == 'inbox'
return 2
1
)()
Run Code Online (Sandbox Code Playgroud)
是的,一个switch表达式:
index = switch segment
when 'index' then 0
when 'inbox' then 2
else 1
Run Code Online (Sandbox Code Playgroud)