I was just trying out the new formatting styles available in javascript, I was pretty stunned by the way the new Yeild iterator works.
A very simple yeild in javascript
The output is as follows:
This is interesting. The yeild statement effectively will halt execution inside a function and allow us to step through values.
Also of note if you try to iterte the function a further tiem after it is “done” you will see the following;
Okay - so it’s probably best to loop through iterators until you see they are “done”…
That’s just a little exploration into generators. It’s an interesting paradigm, and it will definitely open the door to useful ways of writing code.