admin管理员组文章数量:1290955
I've read the MDN definition for await which is :
"The await operator is used to wait for a Promise. It can only be used inside an async function."
which works in the editor. However in the chrome console
I wrote an async function then in the global execution I typed await functionName and that works perfectly without needing to the async function wrapper, edit: is that supported in the chrome's console just ?
const asyncGreeting = async () => 'Greeting'
then in the global execution
await asyncGreeting()
the result was "Greeting"
I've read the MDN definition for await which is :
"The await operator is used to wait for a Promise. It can only be used inside an async function."
which works in the editor. However in the chrome console
I wrote an async function then in the global execution I typed await functionName and that works perfectly without needing to the async function wrapper, edit: is that supported in the chrome's console just ?
const asyncGreeting = async () => 'Greeting'
then in the global execution
await asyncGreeting()
the result was "Greeting"
Share Improve this question edited Aug 12, 2019 at 15:44 Mustafa Alfar asked Aug 12, 2019 at 11:01 Mustafa AlfarMustafa Alfar 1852 gold badges5 silver badges16 bronze badges 4- 3 So the Chrome REPL is weird. Did you have a question? (I see a question mark in your post, but it follows a statement). – Quentin Commented Aug 12, 2019 at 11:04
- 5 This feature was added in Chrome 62 developers.google./web/updates/2017/08/… – Roland Starke Commented Aug 12, 2019 at 11:05
- 1 As Roland wrote, this works already in the console but not for the normal code execution. However, there is a proposal for that github./tc39/proposal-top-level-await – str Commented Aug 12, 2019 at 11:09
- I had same question and this quetsion helps. + 1 – Rick Commented Mar 24, 2020 at 5:03
1 Answer
Reset to default 8Top-level await
is a proposed addition to ECMAScript.
Chrome added support for it to the dev tools.
Hence you can see it working in your test.
本文标签: javascriptawait work in chrome console without async wrapperStack Overflow
版权声明:本文标题:javascript - await work in chrome console without async wrapper - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741516351a2382911.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论