小编Lev*_*_OP的帖子

您可以在 JavaScript 中的 switch case 中使用函数吗

我希望能够在 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(),但它们都不起作用。谢谢!

javascript node.js

2
推荐指数
1
解决办法
2811
查看次数

标签 统计

javascript ×1

node.js ×1