2. Iterator Object
• Object is an Iterator object when it allows to access items from a
collection one at a time.
• Provide next() method to achieve above.
• next() method spits out object of this sort
{value : ”something” , done : true/false}.
3. Iterable interface
• Object must provide default iteration method which returns an
iterator object.
• [Symbol.iterator] is such method in javascript.
• Its automatically gets called by for of loop.
9. Quick Recap
• The Iterable interface require the implementation of a
[Symbol.iterator] method.
• The iterator interface require the implementation of next.
• Why next()?
• Because next method’s result has a done property set to true means the iterator has
been exhausted and the iteration value.
• Most Iterators implement Iterable interface i.e. most of them have
[Symbol.iterator] method.
15. How generators are different?
• Can be pause as many times and resumed later.
• Allowing other code to run during these pause periods.
• ES6 generator functions are "cooperative" in their concurrency
behavior which basically indicates that a process (in our case, a
function) itself chooses when it will allow an interruption, so that it
can cooperate with other code.
• Use yield keyword to pause itself.