iterators & generators
Iterators
Standard built-in object에
Symbol 이 있고,
Symbol.iterator 를 통해
반복처리가 가능하다.
for .. of .. loop
const message = 'hello world';
console.log(message[Symbol.iterator]); // ƒ [Symbol.iterator]() { [native code] }
console.log(message[Symbol.iterator]()); // StringIterator {}
const message = 'hello world';
for(let char of message){
console.log(char); // h
// e
// l
// ...
}
.next function
const message = 'hello world';
const iter = message[Symbol.iterator]();
console.log(iter);