node7 async-await 語法上還不支持

node7正式發佈了,因此想試下比較爽的async-await,畢竟不喜歡使用babel。因而...node

語法上尚未支持async await

test.jsbootstrap

async function test() {
    return 'hello async-await';
}

test().then(function(val) {console.log(val)}).catch(function(err) {console.log(err)});

執行babel

node test.js

居然獲得了async

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,若是想要使用仍是要加上參數.net

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.code

相關文章
相關標籤/搜索