我有一个问题。
async message
和仅(message)
之间有什么区别。
这是异步的例子
client.on('message', async message => {CODE}
这是一个没有异步client.on('message', (message) => {CODE})
我希望你能理解我的问题;)
答案 0 :(得分:0)
(message) => {}
是arrow function,而async message => {}
是async function
本质区别在于,在async
函数中,您可以await
进行异步代码完成。
正如您在mdn page for arrow function expressions中所读到的:
// Parentheses are optional when there's only one parameter name:
(singleParam) => { statements }
singleParam => { statements }
如此
async message => {CODE}
// is equal to
async (message) => {CODE}
和
(message) => {}
// is equal to
message => {}
重要的是要使括号的使用方式保持一致,而在代码中实现100%一致性的最佳方法是使用prettier之类的工具。