未定义Ember> 2.2.0获取regeneratorRuntime

时间:2015-12-31 17:43:28

标签: ember.js ember-cli

所以我在Ember的服务中使用了一个迭代器。代码使用旧样式脚本工作我不能使用ES2015样式

  

ReferenceError:未定义regeneratorRuntime

    stuff[Symbol.iterator] = function *(){
        debugger;
        let properties = Object.keys(this);
        for(let p of properties){
            yield this[p];
        }
    };

我知道这是因为新的' *'操作员的功能。我已经看到了描述必须加载浏览器 - 填充npm的答案https://stackoverflow.com/a/28978619/24862,但我有点不清楚如何在ember框架内使用它。有人做过这个吗?或者我应该放弃,直到恩伯支持它。

2 个答案:

答案 0 :(得分:4)

Polyfill

Babel comes with a polyfill that includes a custom regenerator runtime and core-js. Many transformations will work without it, but for full support you may need to include the polyfill in your app.

You should now include as ember-cli-babel and not as babel. Like this:

var app = new EmberApp(defaults, {
    'ember-cli-babel': {
        includePolyfill: true
    }
}

Regenerator:

This package implements a fully-functional source transformation that takes the syntax for generators/yield from ECMAScript 2015 or ES2015 and Asynchronous Iteration proposal and spits out efficient JS-of-today (ES5) that behaves the same way.

Sources: https://github.com/babel/ember-cli-babel and https://github.com/facebook/regenerator

答案 1 :(得分:2)

也许你对Babel.js的使用需要包含polyfill,在你的ember-cli-build.js文件中使用:

  var app = new EmberApp(defaults, {
    // Add options here
    babel: {
      includePolyfill: true
    }
  });