我希望能够在 switch case 语句上调用函数,但我似乎无法弄清楚。例子:
switch(message.toLowerCase()) {
// the startsWith would be an extension of the message.toLowerCase()
// so that the case would be checking for message.toLowerCase().startsWith("pay")
case startsWith("pay"):
console.log(message)
break
}
Run Code Online (Sandbox Code Playgroud)
我尝试过使用 case.function()、function(case) 和 case function(),但它们都不起作用。谢谢!