
๐ Drag & Drop 2๏ธโฃ Tuple is an array tuple์ JavaScript์๋ ์๊ณ TypeScript์๋ง ์๋ ํ์ ์ด๋ค. ๋ฐ๋ผ์ ํน์ ๋ณ์๋ฅผ tuple ํ์ ์ผ๋ก ์ง์ ํ์ ๋, ์๋์ ๊ฐ์ ๋ฐฉ๋ฒ์ผ๋ก tuple ํ์ ์์ ํ์ธํ ์ ์๋ค. const engineer: [string, string, string] = ['Apeach', 'Ogu', 'Choonsik']; engineer instanceof Tuple; // โ typeof engineer === 'tuple'; // โ (false) But tuple์ TypeScript์๋ง ์กด์ฌํ๋ ํ์ ์ด์ง๋ง JavaScript๋ก ์๊ฐํด๋ดค์ ๋ ๊ฒฐ๊ตญ์ ๋ฐฐ์ด์ด๋ค. ๊ทธ๋ฌ๋ฏ๋ก ์ ์ธํ ๋ณ์๊ฐ tuple์ด ๋ง๋์ง ํ์ธํ๋ ค๋ฉด ๋ฐฐ์ด์ธ์ง ์ฌ๋ถ๋ฅผ ํ์ธ..

Decorators 3๏ธโฃ Validation decorator ํ๋กํผํฐ ๋ฐ์ฝ๋ ์ดํฐ ์์ class Course { title: string; price: number; constructor(t: string, p: number) { this.title = t; this.price = p; } } const courseForm = document.querySelector('form')!; courseForm.addEventListener('submit', event => { event.preventDefault(); const titleEl = document.getElementById('title') as HTMLInputElement; const priceEl = document.getElementB..

Decorators 2๏ธโฃ Decorator the synthetic sugar ํด๋์ค ๋ฐ์ฝ๋ ์ดํฐ๋ constructor๋ฅผ ๋ฐํํ๋ฉด์ ๊ธฐ์กด constructor๋ฅผ ํ์ฅํ ์ ์๋ค. constructor๋ฅผ ํ์ฅํ ๋ super();๋ ๊ธฐ์กด ํด๋์ค ํ์ฅ์์์ ๋ง์ฐฌ๊ฐ์ง๋ก ๊ธฐ์กด ํด๋์ค์ ์ ๋ณด๋ฅผ ๊ธฐ์ตํ๊ณ ์ถ์ ๋ ์ฌ์ฉํ๋ฉด ๋๋ค. function ClassDeco() { return function(target: T) { return class extends target { constructor(..._: any[]) { super(); // not necessary /* write your code */ } } } } @ClassDeco class Person { name = 'Shou'; get name() {..

Decorators 1๏ธโฃ What is Decorators? ํด๋์ค, ํ๋กํผํฐ, ์ก์ธ์, ๋ฉ์๋, ํ๋ผ๋ฏธํฐ์ ์ฒจ๋ถํ ์ ์๋ ํน๋ณํ ํจ์์ด๋ค. ๋ฐ์ฝ๋ ์ดํฐ๊ฐ ๋ถ์ ํด๋์ค ๋ฑ๋ฑ ์์๋ ๋ฐ์ฝ๋ ์ดํฐ์์ ์ ์๋ ๊ธฐ๋ฅ์ด ๋์ํ๋ค. ์ ์ํ ๋ฐ์ฝ๋ ์ดํฐ ํจ์๋ฅผ @ ๊ธฐํธ๋ฅผ ๋ถ์ฌ ์คํํ ์ ์๋ค. function ClassDeco(constructor: Function) { console.log('Logging...'); console.log(constructor); } @ClassDeco class Person { name = 'Shou'; constructor() { console.log('Creating person object...'); } } /* Logging... class Person { constructo..

ํด๋์ค์ ์ธ์คํด์ค โ๏ธ ํด๋์ค ํด๋์ค๋? ํด๋์ค๋ ์์ฑ๊ณผ ๋ฉ์๋๋ฅผ ์ ์ํ๋ ๊ณต๊ฐ์ด๋ค. ์์ฑ์ ํด๋์ค์ ํฌํจ๋๋ ๋ณ์๋ฅผ ์๋ฏธํ๊ณ , ๋ฉ์๋๋ ํด๋์ค์ ํฌํจ๋๋ ํจ์๋ฅผ ์๋ฏธํ๋ค. ํด๋์ค๋ฅผ ์ ์ํ๋ ๋ฐ์๋ 2๊ฐ์ง ๋ฐฉ๋ฒ์ด ์๋ค. ํจ์๋ก ์ ์ (ES5 ๋ฌธ๋ฒ) function Introduce(name, age, favorite) { // ์ธ์คํด์ค ๋ง๋ค์ด์ง ๋ ์คํ๋๋ ์ฝ๋ } class ํค์๋๋ก ์ ์ (ES6 ๋ฌธ๋ฒ) class Introduce { constructor(name, age, favorite) { // ์ธ์คํด์ค๊ฐ ๋ง๋ค์ด์ง ๋ ์คํ๋๋ ์ฝ๋ } } ์ฌ๊ธฐ์ constructor๋ ํด๋์ค๊ฐ ์ธ์คํด์ค ๊ฐ์ฒด๋ฅผ ์์ฑํ ๋ ๊ฐ์ฒด๋ฅผ ์ด๊ธฐํํ๋ ๋ฉ์๋์ด๋ค. constructor ๋ฉ์๋๋ฅผ ๋ค์๊ณผ ๊ฐ์ด ์ฌ์ฉํ๋ค๋ฉด, cla..

๊ฐ์ฒด ์งํฅ ๊ฐ์ฒด ์งํฅ ํ๋ก๊ทธ๋๋ฐ์ด๋? ํ๋์ ์ฒญ์ฌ์ง์ ๋ง๋ค๊ณ ๊ทธ ์ฒญ์ฌ์ง์ ๋ฐํ์ผ๋ก, ์ฆ ์๋ฐ์คํฌ๋ฆฝํธ์์๋ class๋ฅผ ๋ฐํ์ผ๋ก ํ๋ ํ๋์ ๊ฐ์ฒด, ์ฆ instance๋ฅผ ๋ง๋๋ ํ๋ก๊ทธ๋๋ฐ ํจํด์ ์๋ฏธํ๋ค. โ๏ธ ํด๋์ค์ ์ธ์คํด์ค ํด๋์ค๋ ์์ฑ๊ณผ ๋ฉ์๋๋ฅผ ์ ์ํ๋ ๊ณต๊ฐ์ด๊ณ ์ธ์คํด์ค๋ ํด๋์ค์์ ์ ์๋ ์ ๋ณด๋๋ฅผ ๊ฐ์ ธ์ ์ด์ฉํ๋ ๊ฐ์ฒด์ด๋ค. ์์ฑ์ ํด๋์ค์ ํฌํจ๋๋ ๋ณ์๋ฅผ ์๋ฏธํ๊ณ , ๋ฉ์๋๋ ํด๋์ค์ ํฌํจ๋๋ ํจ์๋ฅผ ์๋ฏธํ๋ค. ํด๋์ค๋ฅผ ์ ์ํ๋ ๋ฐ์๋ 2๊ฐ์ง ๋ฐฉ๋ฒ์ด ์๋ค. ํจ์๋ก ์ ์ (ES5 ๋ฌธ๋ฒ) function Introduce(name, age, favorite) { // ์ธ์คํด์ค ๋ง๋ค์ด์ง ๋ ์คํ๋๋ ์ฝ๋ } class ํค์๋๋ก ์ ์ (ES6 ๋ฌธ๋ฒ) class Introduce { constructor(..