Page 148 - JavaScript
P. 148
var beforePrevious = 1;
while(true) {
var current = previous + beforePrevious;
beforePrevious = previous;
previous = current;
yield current; //This is like return but
//keeps the current state of the function
// i.e it remembers its place between calls
}
}
var fib = FibonacciGenerator();
fib.next().value; //2
fib.next().value; //3
fib.next().value; //5
fib.next().done; //false
Read Behavioral Design Patterns online: https://riptutorial.com/javascript/topic/5650/behavioral-
design-patterns
https://riptutorial.com/ 105

