await 关键词


\await keyword

在顶层启用对 await 关键字的支持。

\Support for the await keyword is enabled at the top level.

> await Promise.resolve(123)
123
> await Promise.reject(new Error('REPL await'))
Uncaught Error: REPL await
 at REPL2:1:54
> const timeout = util.promisify(setTimeout);
undefined
> const old = Date.now(); await timeout(1000); console.log(Date.now() - old);
1002
undefined 

在 REPL 中使用 await 关键字的一个已知限制是它会使 constlet 关键字的词法范围无效。

\One known limitation of using the await keyword in the REPL is that it will invalidate the lexical scoping of the const and let keywords.

例如:

\For example:

> const m = await Promise.resolve(123)
undefined
> m
123
> const m = await Promise.resolve(234)
undefined
> m
234 

--no-experimental-repl-await 应禁用 REPL 中的顶层等待。

\--no-experimental-repl-await shall disable top-level await in REPL.

AltStyle によって変換されたページ (->オリジナル) /