请问用node 7.0为什么下面的代码运行不了?
高洛峰
高洛峰 2016-11-01 10:59:59
[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();


高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

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


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

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