Given an ES6 class with generator function how do you run that generator function from ES5 code:
class GeneratorClass {
constructor() {
this.ary = [1, 2, 3];
}
*[Symbol.iterator]() {
for (let el of this.ary) {
yield el;
}
}
}
// This runs fine transcompiled (traceur)
var iterableObj = new GeneratorClass();
for (let el of iterableObj) {
console.log(el);
}
From an ES5 testing framework:
TestCase('GeneratorClassTest', {
setUp: function () {
console.log('in setup');
var iterableObj = new GeneratorClass();
for (var el in this.iterableObj) {
console.log(el);
}
},
testConstructor: function() {
}
});
This does not throw any errors, will run the setup function, however does not iterate through the array.