์ ์ฒด ๊ธ
[ํ์ ์คํฌ๋ฆฝํธ] ์ ๋๋ ์ดํฐ, ๋ฐ๋ณต์(iterator) ์ถ๋ก ๊ณผ ๋ช ์
Generator ํ์ ์คํฌ๋ฆฝํธ๋ Generator๊ฐ yield๋ฅผ ํตํด ๋ฐฉ์ถํ ๊ฐ์ ํ ๋๋ก ๋ฐ๋ณต์์ ํ์ ์ ์ถ๋ก ํ๋ค. ์ ๋๋ ์ดํฐ ํจ์ ๋ฐ๋ณต์(iterator)์ ์ ๋๋ ์ดํฐ๋ ์์๊ด๊ณ๋ค. ์ ๋๋ ์ดํฐ๋ก ๊ฐ์ ์คํธ๋ฆผ์ ์์ฑํ ์ ์๊ณ ๋ฐ๋ณต์๋ก ์์ฑ๋ ๊ฐ์ ์๋นํ ์ ์๊ธฐ ๋๋ฌธ์ด๋ค. ์ดํฐ๋ฌ๋ธ(iterable;๋ฐ๋ณตํ ์ ์๋)Symbol.iterator ๋ผ๋ ํ๋กํผํฐ(๋ฐ๋ณต์๋ฅผ ๋ฐํํ๋ ํจ์)๋ฅผ ๊ฐ์ง ๋ชจ๋ ๊ฐ์ฒด ๋ฐ๋ณต์(iterator)next๋ผ๋ ๋ฉ์๋(value, done ๋ ํ๋กํผํฐ๋ฅผ ๊ฐ์ง ๊ฐ์ฒด๋ฅผ ๋ฐํ)๋ฅผ ์ ์ํ ๊ฐ์ฒด ์๋ฐ์คํฌ๋ฆฝํธ์์ ์ ๋๋ ์ดํฐ ํจ์๋ฅผ ํธ์ถํ๋ฉด ์ดํฐ๋ฌ๋ธ ๋ฐ๋ณต์(IterableIterator)๊ฐ ๋ฐํ๋๋ค. ํ์ ์คํฌ๋ฆฝํธ์์๋ ์ง์ํ๋ค. //๋ค์ ํผ๋ณด๋์น ์ซ์๋ฅผ ๊ณ์ฐํ๊ธฐ ์ํด a์ b๋ฅผ, b์ a+b๋ฅผ..
[AWS EC2] ์ธ์คํด์ค์์ ํฐ์บฃ์ด ์ ์ค์น๋์ง ์๋ ๊ฑด
[JSP]์๋์ฐ์์ ํฐ์บฃ ์ค์น์ ํฐ์บฃ ์๋ฒ ๊ตฌ๋ :: Kamang's IT Blog (tistory.com) [JSP]์๋์ฐ์์ ํฐ์บฃ ์ค์น์ ํฐ์บฃ ์๋ฒ ๊ตฌ๋ ์๋์ฐ์์ ํฐ์บฃ ์ค์น์ ๊ตฌ๋ํ๋ ๋ฒ์ ๋ํด์ ์์๋ณด์. ์ฌ์ค ๋ฆฌ๋ ์ค๋ ๋งฅ์ ์๋์ฐ์ ๋นํ๋ฉด ํจ์ฌ ์ฝ๊ธฐ ๋๋ฌธ์ ๋ฐ๋ก ํฌ์คํ ํ ํ์๋ ์์๊ฒ ๊ฐ๋ค. ๋จผ์ ํฐ์บฃ ์ฌ์ดํธ์ ๋ค์ด๊ฐ๋ค. ๊ทธ ๋ค์ ์ kamang-it.tistory.com
[ํ์ ์คํฌ๋ฆฝํธ] ์ปคํผ๋จธ์ ํด๋์ค๋ง๋ค๊ธฐ ์ค์ต
//์ปคํผ๋จธ์ ๋ง๋ค๊ธฐ type CoffeeCup = { orderShot: number; }; class coffeeMachine { private static ONE_SHOT_CAPSULE: number = 3; private static ONE_CUP_WATER: number = 10; static makeMachine(beans: number, water: number): coffeeMachine { return new coffeeMachine(beans, water); } constructor(private capsule: number = 3, private water: number = 10) {} makeCoffee(orderShot: number): CoffeeCup { if (this.caps..
[ํ์ ์คํฌ๋ฆฝํธ] ์ ๋๋ ์ดํฐ ์ง์, ๋ช ์
์ ๋๋ ์ดํฐ ํจ์ ์ ๋๋ ์ดํฐ ํจ์๋ ์ฌ๋ฌ ๊ฐ์ ๊ฐ์ ์์ฑํ๋ ํธ๋ฆฌํ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ค. ์ ๋๋ ์ดํฐ ํจ์๋ฅผ ์ด์ฉํ๋ฉด ๊ฐ์ ์์ฐํ๋ ์๋๋ ์ ๊ตํ๊ฒ ์กฐ์ ํ ์ ์๋ค. //๋ค์ ํผ๋ณด๋์น ์ซ์๋ฅผ ๊ณ์ฐํ๊ธฐ ์ํด a์ b๋ฅผ, b์ a+b๋ฅผ ํ๋ฒ์ ๋ค์ ํ ๋นํ๋ค. function* createFibonacciGenerator() { let a = 0; let b = 1; while (true) { yield a; [a, b] = [b, a + b]; } } let fiboancciGenerator = createFibonacciGenerator(); //IterableIterator console.log(fiboancciGenerator.next()); //{ value: 0, done: false } console.l..
[์๋ฐ์คํฌ๋ฆฝํธ] ์ ๋๋ ์ดํฐ
Generator ์ ๋๋ ์ดํฐ ํจ์๋ ์ฌ๋ฌ ๊ฐ์ ๊ฐ์ ์์ฑํ๋ ํธ๋ฆฌํ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ค. ์ ๋๋ ์ดํฐ ํจ์๋ฅผ ์ด์ฉํ๋ฉด ๊ฐ์ ์์ฐํ๋ ์๋๋ ์ ๊ตํ๊ฒ ์กฐ์ ํ ์ ์๋ค. ์ ๋๋ ์ดํฐ ํจ์๋ ๊ฒ์ผ๋ฅด๊ฒ ๋์(์ฆ, ์๋น์๊ฐ ์์ฒญํด์ผ๋ง ๋ค์ ๊ฐ์ ๊ณ์ฐ)ํ๊ธฐ ๋๋ฌธ์ ๋ฌดํ์ ๋ชฉ๋ก ์์ฑํ๊ธฐ ๊ฐ์ ๊น๋ค๋ก์ด ๊ธฐ๋ฅ์ ์ ๊ณตํ ์ ์๋ค.) ์ ๋๋ ์ดํฐ ํจ์๋ ๋ค์์ฒ๋ผ ๋์ํ๋ค. //ํจ์๋ช ์์ ๋ถ์ * ์ ์ด ํจ์๊ฐ ์ ๋๋ ์ดํฐ์์ ์๋ฏธํ๋ค. //์ ๋๋ ์ดํฐ๋ฅผ ํธ์ถํ๋ฉด ์ดํฐ๋ฌ๋ธ ๋ฐ๋ณต์๊ฐ ๋ดํ function* createFibonacciGenerator() { let a = 0; let b = 1; while (true) { yield a; [a, b] = [b, a + b]; } } //๋ค์ ํผ๋ณด๋์น ์ซ์๋ฅผ ๊ณ์ฐํ๊ธฐ ์ํด a์ b๋ฅผ, b์..
[ํ์ ์คํฌ๋ฆฝํธ] this ๊ด๋ จ ์ค๋ฅ
function fancyDate() { return console.log( `${this.getDate()} / ${this.getMonth()} / ${this.getFullYear()}` ); } fancyDate.call(new Date()); src/index.ts:74:8 - error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation. 74 `${this.getDate()} / ${this.getMonth()} / ${this.getFullYear()}` ~~~~ src/index.ts:74:28 - error TS2683: 'this' implicitly has type 'any' becau..
[ํ์ ์คํฌ๋ฆฝํธ] class์ getter์ setter
class User { firstName: string; lastName: string; fullName: string; constructor(firstName: string, lastName: string) { this.firstName = firstName; this.lastName = lastName; this.fullName = `${firstName} ${lastName}`; } } let user = new User("Steve", "Jobs"); console.log(user.fullName); //Steve Jobs console.log(user.firstName); //Steve user.firstName = "Jimmy"; console.log(user.fullName); //Steve..