我正在 node 中试验await
关键字.js.我有一个测试脚本:
"use strict";
function x() {
return new Promise(function(resolve, reject) {
setTimeout(function() {
resolve({a:42});
},100);
});
}
await x();
但当我在node中运行它时
await x();
^
SyntaxError: Unexpected identifier
不管我是用node
还是node --harmony-async-await
运行它,还是在 node 中运行.我的Mac电脑上的js'repl'带有 node .js 7.5或 node .js 8(夜间构建).
奇怪的是,同样的代码在Runkit JavaScript笔记本环境中也能工作:https://runkit.com/glynnbird/58a2eb23aad2bb0014ea614b
我做错了什么?