我想做这样的事情
switch (this.dealer) {
case 1-4:
// Do something.
break;
case 5-8:
// Do something.
break;
case 9-11:
// Do something.
break;
default:
break;
}
什么是正确的语法?在 JavaScript 中可以吗?
What is the right syntax for this? Is it possible in JavaScript?
所以 this.dealer
是一个整数,如果它在这些值之间,就做点什么.
So this.dealer
is an integer, and if it's between those values, do something.
这是我想出来的另一种方法:
Here is another way I figured it out:
const x = this.dealer;
switch (true) {
case (x < 5):
alert("less than five");
break;
case (x < 9):
alert("between 5 and 8");
break;
case (x < 12):
alert("between 9 and 11");
break;
default:
alert("none");
break;
}
这篇关于在 JavaScript 中打开整数范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!