请问用node 7.0为什么下面的代码运行不了?

据说node7.0已经支持async/await,那么下面的代码为什么运行不了?

var sleep=function(time){
    return new Promise(function(resolve,reject){
        setTimeout(function(){
            resolve('ok');
        },time);
    });
};

async function start(){
    let result =await sleep(3000);
    console.log(result);
}

start();
阅读 2.8k
1 个回答
node --harmony myapp.js

https://nodejs.org/en/docs/es6/

All ECMAScript 2015 (ES6) features are split into three groups for shipping, staged, and in progress features:

  • All shipping features, which V8 considers stable, are turned on by default on Node.js and do NOT require any kind of runtime flag.

  • Staged features, which are almost-completed features that are not considered stable by the V8 team, require a runtime flag: --harmony.

  • In progress features can be activated individually by their respective harmony flag, although this is highly discouraged unless for testing purposes. Note: these flags are exposed by V8 and will potentially change without any deprecation notice.

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题