🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
也可以更进一步的限制模式,通过使用 `case ... if(condition):` 语法: > It is also possible to further restrict patterns with the case ... if(condition): syntax: ~~~ var myArray = [7, 6]; var s = switch(myArray) { case [a, b] if (b > a): b + ">" +a; case [a, b]: b + "<=" +a; case _: "found something else"; } trace(s); // 6<=7 ~~~ 第一个情况有一个附加的守护条件 if(b>a) 。只有条件满足case才被采用,否则匹配继续下一个case 。 > The first case has an additional guard condition if (b > a). It will only be selected if that condition holds, otherwise matching continues with the next case.