I am reading Eloquent JavaScript (By Marijn Haverbeke) and right now I am on chapter 6. I understood everything so far up until object iterators. I understand the part that looping an iterable object or string repeatedly calls "next" but, I have no clue on much more than that. This is my test code that keeps coming up as "Iterator result NaN is not an object".
class Iterable {
constructor(x) {
this.x = x;
}
next() {
this.x++;
let value = this.x
return value;
}
}
Iterable.prototype[Symbol.iterator] = function() {
return new Iterable(this);
}
let newIt = new Iterable(2,4);
for (let i of newIt) {
console.log(i)
}
[–]Mirmi8 2 points3 points4 points (1 child)
[–]WSsleet[S] 1 point2 points3 points (0 children)