Switch case statement in coffee script

前端 未结 2 1780
春和景丽
春和景丽 2021-02-06 20:34

I have a few different buttons that are calling the same function and I would like to have them wrapped in a switch statement instead of using a bunch of else if conditions. Any

2条回答
  •  别跟我提以往
    2021-02-06 20:53

    In addition to the details in the accepted answer, switch statements in CoffeeScript also supports , to provide multiple match results:

    switch someVar
        when val3, val4 then ...
        else ...
    

    or (if your statements has multiple lines):

    switch someVar
        when val3, val4
            ...
        else
            ...
    

提交回复
热议问题