2.5.4 이터러블 프로토콜
function makeIterator(array) {
var nextIndex = 0;
return {
next: function() {
return nextIndex < array.length
? { value: array[nextIndex++], done: false }
: { done: true};
}
};
}
const iterableObj = {
[Symbol.iterator]() { return makeIterator([1, 2, 3]); }
};for (const elem of iterableObj) {
console.log(elem);
}
// 1
// 2
// 3Last updated