생성기

    [33-js-concepts] 24. 컬렉션과 생성기 (Collections and Generators)

    컬렉션과 생성기 (Collections and Generators) Iterable vs Iterator Iterable과 Iterator 모두 ES5에서 추가된 새로운 규약(protocol)이다. Iterable 반복 가능한 객체들을 말한다. 프로퍼티로 Symbol.iterator를 반드시 가져야 Iterable한 객체로 정의될 수 있다. Array나 Map 같은 컬렉션들은 기본적으로 Iterable한 객체로 설정되어 있으며 일반 Object는 가지고 있지 않다. String 같은 빌트인 객체도 Iterable한 객체로 설정되어 있다. Iterable한 객체들은 아래와 같은 연산이 가능하다. for..of 구문을 통한 객체 접근 ( for child of someIterableObj ) Spread 연..