์ธํŒŒ

You Can Become A

Programme

๋Šฆ๊ฒŒ ์‹œ์ž‘ํ•ด๋„ ๋ˆ„๊ตฌ๋“ ์ง€ ๋…ธ๋ ฅํ•˜๋ฉด ๊ฐœ๋ฐœ์ž๊ฐ€ ๋ ์ˆ˜ ์žˆ์–ด์š” !

yield

๊ณต๋ถ€ํ•œ ๋‚ด์šฉ์„ ์ •๋ฆฌํ•ฉ๋‹ˆ๋‹ค
JavaScript

[JS] ๐Ÿ“š ์ œ๋„ˆ๋ ˆ์ดํ„ฐ - ์ดํ„ฐ๋ ˆ์ดํ„ฐ ๊ฐ•ํ™”ํŒ

์ œ๋„ค๋ ˆ์ดํ„ฐ๋ž€? ์ดํ„ฐ๋Ÿฌ๋ธ”์ด๋ฉฐ ๋™์‹œ์— ์ดํ„ฐ๋ ˆ์ดํ„ฐ = ์ดํ„ฐ๋ ˆ์ดํ„ฐ๋ฅผ ๋ฆฌํ„ดํ•˜๋Š” ํ•จ์ˆ˜ (async๊ฐ€ Promise๋ฅผ ๋ฆฌํ„ดํ•˜๋Š” ํ•จ์ˆ˜๋“ฏ์ด, ์ œ๋„ˆ๋ ˆ์ดํ„ฐ๋Š” ์ดํ„ฐ๋ ˆ์ดํ„ฐ๋ฅผ ๋ฆฌํ„ดํ•˜๋Š” ํ•จ์ˆ˜๋‹ค.) โ€‹ ์ œ๋„ˆ๋ ˆ์ดํ„ฐ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ดํ„ฐ๋ ˆ์ด์…˜ ํ”„๋กœํ† ์ฝœ์„ ์ค€์ˆ˜ํ•ด ์ดํ„ฐ๋Ÿฌ๋ธ”์„ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ์‹๋ณด๋‹ค ๊ฐ„ํŽธํ•˜๊ฒŒ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค. (Promise์™€ async ๊ด€๊ณ„์™€ ๋น„์Šทํ•˜๊ฒŒ ๋ณด๋ฉด ๋œ๋‹ค.) โ€‹ โ€‹ ์ดํ„ฐ๋Ÿฌ๋ธ” ํ”„๋กœํ† ์ฝœ ๋ฐฉ์‹ let range = { from: 1, to: 5, [Symbol.iterator]() { return { current: this.from, last: this.to, next() { if (this.current generatorObj.next() -> yield 2 -> ... -> end โ— ์ œ๋„ˆ๋ ˆ์ดํ„ฐ์˜ ์‹คํ–‰ ๊ฒฐ๊ณผ๊ฐ€ ์ดํ„ฐ๋ ˆ์ด์ดํ„ฐ..

category_image
์ธํŒŒ_
2021.10.06
(0)