객체 자체를 Iterable하게 만들어주는 거시기

class A {
  constructor(x, y, z) {
    this.x = x;
    this.y = y;
    this.z = z;
  }

  *[ Symbol.iterator ]() {
		yield this.x;
		yield this.y;
		yield this.z;
	}
}

const v = new A(1, 2, 3);

console.log(v);
console.log(...v)
console.log([...v])

for (const i of v) {
  console.log(i)
}

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다