javascript - 请问用node 7.0为什么下面的代码运行不了?
伊谢尔伦
伊谢尔伦 2017-04-10 17:28:30
[JavaScript讨论组]

据说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();
伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

全部回复(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 inpidually 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.

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号