target es3 에서 forEach

이터레이터란?

대에충 만든 커스텀 이터러블

class CustomIterable implements Iterable<string> {
  name: string = 'max';
  index: number = 0;

  [Symbol.iterator]() {
    const iterator: Iterator<string> = {
      next: () => ({
        value: this.name[this.index++],
        done: !this.name[this.index - 1],
      }),
    };

    return iterator;
  }
}

const iter = new CustomIterable();

for (const str of iter) {
  console.log('hello', str);
}

커스텀 이터러블을 for of 에서 쓰려면 컴파일 설정이 필요하다.

"downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */

Decorator