GENERATORS
Generators are a delightfully flexible construct introduced in the ECMAScript 6 specification that offers the ability to pause and resume code execution inside a single function block. The implications of this new ability are profound; it allows for, among many other things, the ability to define custom iterators and implement coroutines.
Generator Basics
Generators take the form of a function, and the generator designation is performed with an asterisk. Anywhere a function definition is valid, a generator function definition is also valid:
// Generator function declarationfunction* generatorFn() {}// Generator function expressionlet generatorFn = function* () {}// Object literal method generator functionlet foo = {* generatorFn() {}}// Class instance method generator functionclass Foo {* generatorFn() {}}// Class static method generator functionclass Bar {static * generatorFn() {}}