异步箭头功能的语法 [英] Syntax for async arrow function

查看:120
本文介绍了异步箭头功能的语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用 async 关键字将javascript函数标记为async(即返回一个promise)。像这样:

I can mark a javascript function as "async" (i.e. returning a promise) with the async keyword. Like this:

async function foo() {
  // do something
}

箭头函数的等效语法是什么?

What is the equivalent syntax for arrow functions?

推荐答案

异步箭头函数如下所示:

const foo = async () => {
  // do something
}

匿名 form也可以:

const foo = async function() {
  // do something
}

异步函数声明如下所示:

async function foo() {
  // do something
}

回调中使用异步功能

const foo = event.onCall(async () => {
  // do something
})

这篇关于异步箭头功能的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆