使用.includes()时,Switch语句不起作用
client.on('chat', function(channel, userstate, message, self){ switch(message){ case message.includes(emotes[0]): numberOfEmotes[0]++; console.log("Emote0 has been used " + numberOfEmotes[0] + " time(s)"); break; case message.includes(emotes[1]): numberOfEmotes[1]++; console.log("Emote1 has been used " + numberOfEmotes[1] + " time(s)"); break; case message.includes(emotes[2]): numberOfEmotes[2]++; console.log("Emote2 has been used " + numberOfEmotes[2] + " time(s)"); break; case message.includes(emotes[3]): numberOfEmotes[3]++; console.log("Emote3 has been used " + numberOfEmotes[3] + " time(s)"); break; } /* if(message.includes(emotes[0])){ numberOfEmotes[0]++; console.log("Emote0 has been used " + numberOfEmotes[0] + " time(s)"); }*/ //console.log("** " + message + " **"); });
当函数chat.on被称为带有string的消息的variables应该通过switch语句运行时,我有一个数组与不同的string,如果消息包含该数组中的string,运行大小写。 但是什么也没有发生,这一切似乎正确这里可能是错误的?
开关不能按照你所期望的方式工作。 它将开关中写入的值与大小写块中的每个值进行比较。 所以在你的情况下,它会比较true / false与值的消息,它不会find相同的值,因此没有什么会发生。 你必须使用else语句或parsing消息,并排除Message'type / emote1'的值,然后将所有内容解压缩并放入交换机
- 为什么console.log(10150141932135203)在Firefox和Chrome中打印10150141932135204,以及如何处理这些大整数值?
- ES6类中的constr.apply(this,args)
- 你如何创build一个命名的asynchronous箭头function?
- 如何在Intellij中的GLOBAL范围内使用Node.js库启用代码完成?
- 发送JSON响应给JQuery
- Node.js结合mongoose和Sails水线
- MongoDB:将数组添加到现有的数组中
- 如何从DynamoDB列表中删除地图列表中的Map属性值?
- 我如何加载ICanHaz.js模板与node.js?