gpt4 book ai didi

javascript - CoffeeScript 切换无中断

转载 作者:行者123 更新时间:2023-12-03 06:53:14 25 4
gpt4 key购买 nike

是否可以在coffeescript中使用switch而不中断?

switch code                      switch (code) {
when 37 then case 37: break;
when 38 then -> case 38: break;
when 39 then case 39: break;
when 40 case 40:
... ...

我认为这会起作用但失败了:

switch code
when 37 then continue
when 38 then continue -> not valid
when 39 then continue
when 40
...

最佳答案

不是真的。来自 the docs :

Switch statements in JavaScript are a bit awkward. You need to remember to break at the end of every case statement to avoid accidentally falling through to the default case. CoffeeScript prevents accidental fall-through, and can convert the switch into a returnable, assignable expression. The format is: switch condition, when clauses, else the default case.

不过,如果要同等对待的话,您可以在一个 case 中指定多个值:

switch day
when "Mon" then go work
when "Tue" then go relax
when "Thu" then go iceFishing
when "Fri", "Sat"
if day is bingoDay
go bingo
go dancing
when "Sun" then go church
else go work

关于javascript - CoffeeScript 切换无中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10502079/

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