博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何在ES模块中使用顶级等待
阅读量:2504 次
发布时间:2019-05-11

本文共 1085 字,大约阅读时间需要 3 分钟。

recently introduced top-level await for ES modules. It’s a new proposed standard for ECMAScript, which has .

最近引入了ES模块的顶级await 。 这是ECMAScript的新提议标准,现已 。

Note: it’s going to take some time before this feature will be usable in the production Node.js and in Chrome, but it’s worth taking a look

注意:要在生产中的Node.js和Chrome中使用此功能需要花费一些时间,但值得一看

Right now we can use await only inside async functions. So it’s common to declare an immediately invoked async function expression to wrap it:

现在,我们只能在异步函数中使用await。 因此,通常需要声明立即调用的异步函数表达式来包装它:

(async () => {  await fetch(/* ... */)})()

or also declare a function and then call it:

或也声明一个函数然后调用它:

const doSomething = async () => {  await fetch(/* ... */)}doSomething()

Top-level await will allow us to simply run

顶级等待将使我们能够简单地运行

await fetch(/* ... */)

without all this boilerplate code.

没有所有这些样板代码。

With a caveat: this only works in ES modules. You can’t use this syntax outside of .

注意:仅在ES模块中有效 。 您不能在之外使用此语法。

Normal scripts, and CommonJS modules, will continue to use or creating ad-hoc function like always.

普通脚本和CommonJS模块将像往常一样继续使用或创建即席函数。

翻译自:

转载地址:http://amqgb.baihongyu.com/

你可能感兴趣的文章
用DataReader 分页与几种传统的分页方法的比较
查看>>
看起来像是PS的照片,实际上却令人难以置信!
查看>>
随笔一则
查看>>
WEB 小案例 -- 网上书城(一)
查看>>
加入博客园八个月了
查看>>
怎样实现前端裁剪上传图片功能
查看>>
python flask 如何修改默认端口号
查看>>
Map<String,Object> map=new HashMap<String,Object>详解
查看>>
实现tap的多种方式
查看>>
UVA - 10494 If We Were a Child Again
查看>>
html5 canvas 渲染像素混合模式
查看>>
【hexo】01安装
查看>>
CI框架源码学习笔记2——Common.php
查看>>
005---书籍添加和编辑的提交数据
查看>>
使用case语句给字体改变颜色
查看>>
JAVA基础-多线程
查看>>
面试题5:字符串替换空格
查看>>
JSP九大内置对象及四个作用域
查看>>
OCAC公告
查看>>
Modernizr.js介绍与使用
查看>>