gpt4 book ai didi

CoffeeScript 重构

转载 作者:行者123 更新时间:2023-12-01 09:32:34 28 4
gpt4 key购买 nike

是否有任何特定于 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com