javascript:从switch语句中的一个case转到默认值

时间:2015-05-27 00:21:22

标签: javascript

如何在Javascript中执行此操作?

switch(c){
          case 'a':
                 //do something, condition does not match so go to default case
                 //don't break in here, and don't allow fall through to other cases.
          case 'b':
                 //..
          case 'c':
                 //..
          case '_':
                 //...
          default:
                 //
                 break;
}

这几乎是Jumping from one case to the default case in switch statement的副本,但是没有javascript的解决方案,所以我必须添加这个新帖子。

1 个答案:

答案 0 :(得分:1)

根据您的使用情况,可能有效的另一个选项是将default案例移出交换机。

switch(c){
      case 'a':
             //do something, condition does not match so go to default case
             //don't break in here, and don't allow fall through to other cases.
      case 'b':
             //..
      case 'c':
             //..
      case '_':
             //...
}

// Do the `default/finally` here instead