function* helloWorldGenerator() { yield 'hello'; yield 'world'; return 'ending';}var hw = helloWorldGenerator();console.log(hw.next());环境是配置的babel,练了一天ES6都没问题,但是一旦用Generator函数就报这错,请问怎么解决?下面是我配置的环境
1 回答

RISEBY
TA贡献1856条经验 获得超5个赞
现在来回答一下自己的问题,也方便遇到同样写es6却报上图红字错误的同志们,咯咯咯咯~ 我真棒~
首先babel基础包(不安装额外东西)并不是支持完整的es6语言,加上浏览器也不是支持所有的es6语言,如果你写的es6语言刚好撞上这样的情况了.
那么就需要babel的拓展包(Polyfill),网址链接描述
这是一个补完babel支持es6的拓展包,配置步骤为3个
1.打开命令行键入 npm install --save-dev babel-polyfill 安装polyfill
2.在webpack.config.js中最上面写上var babelpolyfill = require("babel-polyfill");
3.在自己的项目js文件中最开头写上import "babel-polyfill";
OK 这样就解决了 嘿嘿嘿
添加回答
举报
0/150
提交
取消