return {
next: function() {
return nextIndex < array.length ?
{value: array[nextIndex++], done: false} :
{done: true};
}
};
}
var it = makeIterator(['yo', 'ya']);
console.log(it.next()); // 'yo'
console.log(it.next()); // 'ya'
console.log(it.next()); // true
Could somebody explain me how the makeIterator function know what was it's last index?
makeIterator runs: * defines nextIndex every time next runs: * increments nextIndex
Обсуждают сегодня