是否有任何特定于 CoffeeScript 的技巧可以使这看起来更整洁:
index = (->
if segment == 'index'
return 0
else if segment == 'inbox'
return 2
1
)()
最佳答案
是的,一个switch
表达式:
index = switch segment
when 'index' then 0
when 'inbox' then 2
else 1
关于 CoffeeScript 重构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13607777/