ES2022版本后,ASYNC关键字将是什么?
我只是很好奇,根据es2022
发布我们可以使用顶级等待
,这意味着我们不需要使用async
使用的关键字来使用等待
,在ES2022
发布之前,我们不允许我们编写等待
没有async
。
那么,现在使用async
关键字是什么?是否还有其他用例可以使用async
关键字?
I am just curious, as per ES2022
release we can use top level await
and that means we don't need to use async
keyword to use await
, before es2022
release we were not allowed to write await
without async
.
So what will be the use of async
keyword now? Is there are any other use cases where we can utilize async
keyword?
Reference -
What’s new in JavaScript after the ES2022 release
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
顶级等待不是替换异步函数。您仍然会(永远)(永远)
这样做或更复杂的事情,因为等待只能在异步函数中使用 - 允许在顶层等待
等待
不会改变这一点。功能是模块化编程的基础。顶级等待着,只是在那里使语法变得更加容易 - 它不会从根本上改变语言或使函数过时。
Top-level await does not replace async functions. You will still (and forever) be forbidden to do
or anything more complicated than that, because await can only used in an async function - and permitting
await
on the top level doesn't change that.Functions are the building blocks of modular programming. Top-level await is only there to make the syntax a bit easier - it doesn't fundamentally change the language or make functions obsolete.
如果您想在功能中使用等待。
If you ever want to use await inside a function.