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 关键字的一个已知限制是,它会使 const 和 let 关键字的词法作用域失效。
【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 中禁用顶层 await。