node7正式发布了,所以想试下比较爽的async-await,毕竟不喜欢使用babel。于是...
语法上还没有支持async await
test.js
async function test() {
return 'hello async-await';
}
test().then(function(val) {console.log(val)}).catch(function(err) {console.log(err)});
执行
node test.js
竟然得到了
async function test() {}
^^^^^^^^
SyntaxError: Unexpected token function
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:545:28)
at Object.Module._extensions..js (module.js:582:10)
at Module.load (module.js:490:32)
at tryModuleLoad (module.js:449:12)
at Function.Module._load (module.js:441:3)
at Module.runMain (module.js:607:10)
at run (bootstrap_node.js:382:7)
at startup (bootstrap_node.js:137:9)
at bootstrap_node.js:497:3
说明node7还没有在语法上直接支持async await,如果想要使用还是要加上参数
node --hamony-asyc-await test.js
啥子时候呢
Node.js v8, the next stable version containing the V8 version that enables async/await operations will be released in April 2017. Till that time you can still experiment with it using the unstable Node.js v7 branch.