我可以用async
关键字将JavaScript函数标记为"async"(即返回promise ).这样地:
async function foo() {
// Do something
}
箭头函数的等效语法是什么?
我可以用async
关键字将JavaScript函数标记为"async"(即返回promise ).这样地:
async function foo() {
// Do something
}
箭头函数的等效语法是什么?
Async arrow functions如下所示:
const foo = async () => {
// do something
}
对于传递给它的single argument,Async arrow functions如下所示:
const foo = async evt => {
// do something with evt
}
对于传递给它的multiple arguments,异步arrow functions如下所示:
const foo = async (evt, callback) => {
// do something with evt
// return response with callback
}
anonymous表格也适用:
const foo = async function() {
// do something
}
异步函数declaration如下所示:
async function foo() {
// do something
}
在callback中使用异步函数:
const foo = event.onCall(async () => {
// do something
})
在class中使用async method:
async foo() {
// do something
}