3 ms·
Generally? Yes, for example for an array like data structure it would make sense to have methods on the data structure and make it iterable by providing a `Symb
by inglor 12y ago
Generally? Yes, for example for an array like data structure it would make sense to have methods on the data structure and make it iterable by providing a `Symbol.iterator` - in this case it can be avoided a generator is just a function that returns an iterable sequence (i.e. a sequence using the new ES iteration protocol) so usage would be different - you'd invoke it in a for...of instead of just iterating it.
- scotty79 12y agoGeneral usage I get. I just don't see the point of using it in this example. Everything else can be explained by 'I wan't my data structures to be immutable and lazy'. Symbol.iterator just seems like purposeless showing off. As for your last point, you wouldn't have to invoke in for...of if you returned generator instance, not generator function from your code.
- madeofpalk 12y ago> Symbol.iterator just seems like purposeless showing off. That's the point.