Goal: Understand what this passage from "You Don't Know JS" means exactly and what JS is doing when you create an iterator.
Quoted Passage (Get Started - Chaper 3):
https://github.com/getify/You-Dont-Know-JS/blob/2nd-ed/get-started/ch3.md
"You may have noticed a nuanced shift that occurred in this discussion. We started by talking about consuming iterators, but then switched to talking about iterating over iterables. The iteration-consumption protocol expects an iterable, but the reason we can provide a direct iterator is that an iterator is just an iterable of itself! When creating an iterator instance from an existing iterator, the iterator itself is returned."
I tried to write-up what my understanding of this passage is, but in truth it just doesn't make sense to me. Questions:
- Are we returning an instance of an iterator from a prototype/class iterator or are is the prototype/class itself used?
- What does an "iterable of itself" even mean?
- Is an iterator declared and instantiated by
let i = 0; i < ...
? and referenced by thei
or is it something more behind the scenes?