我有个问题。async message
和 only有什么区别(message)
。这是异步的示例
client.on('message', async message => {CODE}
这是一个没有异步的例子client.on('message', (message) => {CODE})
我希望你能理解我的问题;)
我有个问题。async message
和 only有什么区别(message)
。这是异步的示例
client.on('message', async message => {CODE}
这是一个没有异步的例子client.on('message', (message) => {CODE})
我希望你能理解我的问题;)
(message) => {}
是一个箭头函数并且async message => {}
是一个异步函数
本质区别在于,在一个async
函数中你可以await
进行异步代码补全。
您可以在mdn 页面中阅读箭头函数表达式:
// 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之类的工具。