<small id='NIaty'></small><noframes id='NIaty'>

    <tfoot id='NIaty'></tfoot>
      <i id='NIaty'><tr id='NIaty'><dt id='NIaty'><q id='NIaty'><span id='NIaty'><b id='NIaty'><form id='NIaty'><ins id='NIaty'></ins><ul id='NIaty'></ul><sub id='NIaty'></sub></form><legend id='NIaty'></legend><bdo id='NIaty'><pre id='NIaty'><center id='NIaty'></center></pre></bdo></b><th id='NIaty'></th></span></q></dt></tr></i><div id='NIaty'><tfoot id='NIaty'></tfoot><dl id='NIaty'><fieldset id='NIaty'></fieldset></dl></div>
      <legend id='NIaty'><style id='NIaty'><dir id='NIaty'><q id='NIaty'></q></dir></style></legend>

        <bdo id='NIaty'></bdo><ul id='NIaty'></ul>

    1. JavaScript,Typescript switch 语句:两种情况下运行相同代码的方式?

      时间:2023-09-07
        <legend id='p6cmI'><style id='p6cmI'><dir id='p6cmI'><q id='p6cmI'></q></dir></style></legend>
          <tbody id='p6cmI'></tbody>

          <i id='p6cmI'><tr id='p6cmI'><dt id='p6cmI'><q id='p6cmI'><span id='p6cmI'><b id='p6cmI'><form id='p6cmI'><ins id='p6cmI'></ins><ul id='p6cmI'></ul><sub id='p6cmI'></sub></form><legend id='p6cmI'></legend><bdo id='p6cmI'><pre id='p6cmI'><center id='p6cmI'></center></pre></bdo></b><th id='p6cmI'></th></span></q></dt></tr></i><div id='p6cmI'><tfoot id='p6cmI'></tfoot><dl id='p6cmI'><fieldset id='p6cmI'></fieldset></dl></div>
            1. <tfoot id='p6cmI'></tfoot>

                <bdo id='p6cmI'></bdo><ul id='p6cmI'></ul>

                <small id='p6cmI'></small><noframes id='p6cmI'>

              • 本文介绍了JavaScript,Typescript switch 语句:两种情况下运行相同代码的方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                有没有一种方法可以在不复制和粘贴的情况下将两个不同的 case 值分配给同一个代码块?比如68以下和40应该执行相同的代码,而30是不相关的.

                Is there a way to assign two different case values to the same block of code without copy and pasting? For example, below 68 and 40 should execute the same code, while 30 is not related.

                case 68:
                   //Do something
                break;
                
                case 40:
                   //Do the same thing
                break;
                
                case 30:
                   //Do something different
                break;
                

                认为这样的事情应该有效(即使它显然没有)是不正确的吗?

                Is it incorrect to think something like this should work (even though it obviously doesn't)?

                case 68 || 40:
                   //Do something
                break;
                
                case 30:
                   //Do something else
                break;
                

                推荐答案

                把它们一个接一个地放在一起就行了

                Just put them right after each other without a break

                switch (myVar) {
                  case 68:
                  case 40:
                    // Do stuff
                  break;
                
                  case 30:
                    // Do stuff
                  break;
                }
                

                这篇关于JavaScript,Typescript switch 语句:两种情况下运行相同代码的方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:JavaScript函数没有将我的参数传递给其他函数 下一篇:es6 中的 case 之后的 switch 语句中的花括号有什么作用?

                相关文章

                <small id='V7rr8'></small><noframes id='V7rr8'>

                  1. <tfoot id='V7rr8'></tfoot>
                    <i id='V7rr8'><tr id='V7rr8'><dt id='V7rr8'><q id='V7rr8'><span id='V7rr8'><b id='V7rr8'><form id='V7rr8'><ins id='V7rr8'></ins><ul id='V7rr8'></ul><sub id='V7rr8'></sub></form><legend id='V7rr8'></legend><bdo id='V7rr8'><pre id='V7rr8'><center id='V7rr8'></center></pre></bdo></b><th id='V7rr8'></th></span></q></dt></tr></i><div id='V7rr8'><tfoot id='V7rr8'></tfoot><dl id='V7rr8'><fieldset id='V7rr8'></fieldset></dl></div>

                      <bdo id='V7rr8'></bdo><ul id='V7rr8'></ul>
                    <legend id='V7rr8'><style id='V7rr8'><dir id='V7rr8'><q id='V7rr8'></q></dir></style></legend>