How Do You Create a Generator?
Problem
You want to know what a generator is and how you make one.
Solution
Generators are functions that do not immediately execute when called on. They return an iterator object that lets you call and pass parameters at another time. You can continue to call this function until the first yield expression is executed.
The Code
Listing 13-1. Creating a Generator
function * helloGenerator(){
yield 'HELLOFRIEND';
}
var sayHello- = helloGenerator();
console.log(sayHello) //returns generator
//console.log(sayHello.next()) ...