我可以使用async
关键字将javascript函数标记为“异步”(即返回承诺)。像这样:
async function foo() {
// do something
}
箭头功能的等效语法是什么?
异步箭头功能的语法
我可以使用async
关键字将javascript函数标记为“异步”(即返回承诺)。像这样:
async function foo() {
// do something
}
箭头功能的等效语法是什么?
第1513篇《异步箭头功能的语法》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点
您也可以这样做:
YourAsyncFunctionName = async (value) => {
/* Code goes here */
}
异步箭头函数如下所示:
const foo = async () => {
// do something
}
传递给它的单个参数的异步箭头函数如下所示:
const foo = async evt => {
// do something with evt
}
The anonymous form works as well:
const foo = async function() {
// do something
}
An async function declaration looks like this:
async function foo() {
// do something
}
Using async function in a callback:
const foo = event.onCall(async () => {
// do something
})
带参数的异步箭头函数语法
const myFunction = async (a, b, c) => {
// Code here
}
相似问题
问题类别
立即调用异步箭头功能:
立即调用异步函数表达式: