在没有异步包装的情况下在chrome控制台中等待工作 [英] await work in chrome console without async wrapper
问题描述
我已阅读MDN的定义,它是:
"await运算符用于等待Promise.它只能在异步函数中使用."
在编辑器中工作.但是在Chrome控制台中
我编写了一个异步函数,然后在全局执行中键入了一个waitFunctionName,它可以完美运行而无需异步函数包装, edit:Chrome的控制台仅支持该函数吗?
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'
然后在全局执行中
await asyncGreeting()
结果是问候"
推荐答案
顶级await
是ECMAScript的拟议补充.
Top-level await
is a proposed addition to ECMAScript.
Chrome 为此添加了支持开发工具.
Chrome added support for it to the dev tools.
因此,您可以在测试中看到它的作用.
Hence you can see it working in your test.
这篇关于在没有异步包装的情况下在chrome控制台中等待工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!