Dream๐Ÿฐng
article thumbnail
[TS] Drag & Drop 2๏ธโƒฃ
๐Ÿ“ Study/TypeScript 2023. 3. 30. 01:33

๐Ÿ‘ 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์ด ๋งž๋Š”์ง€ ํ™•์ธํ•˜๋ ค๋ฉด ๋ฐฐ์—ด์ธ์ง€ ์—ฌ๋ถ€๋ฅผ ํ™•์ธ..

article thumbnail
[TS] Decorators 3๏ธโƒฃ
๐Ÿ“ Study/TypeScript 2023. 3. 24. 19:36

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..

article thumbnail
[TS] Decorators 2๏ธโƒฃ
๐Ÿ“ Study/TypeScript 2023. 3. 22. 11:56

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() {..

article thumbnail
[TS] Decorators 1๏ธโƒฃ
๐Ÿ“ Study/TypeScript 2023. 3. 20. 12:51

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..

article thumbnail
[JS] ํด๋ž˜์Šค์™€ ์ธ์Šคํ„ด์Šค
๐Ÿ“ Study/JavaScript 2022. 9. 21. 17:30

ํด๋ž˜์Šค์™€ ์ธ์Šคํ„ด์Šค โœ๏ธ ํด๋ž˜์Šค ํด๋ž˜์Šค๋ž€? ํด๋ž˜์Šค๋Š” ์†์„ฑ๊ณผ ๋ฉ”์†Œ๋“œ๋ฅผ ์ •์˜ํ•˜๋Š” ๊ณต๊ฐ„์ด๋‹ค. ์†์„ฑ์€ ํด๋ž˜์Šค์— ํฌํ•จ๋˜๋Š” ๋ณ€์ˆ˜๋ฅผ ์˜๋ฏธํ•˜๊ณ , ๋ฉ”์†Œ๋“œ๋Š” ํด๋ž˜์Šค์— ํฌํ•จ๋˜๋Š” ํ•จ์ˆ˜๋ฅผ ์˜๋ฏธํ•œ๋‹ค. ํด๋ž˜์Šค๋ฅผ ์ •์˜ํ•˜๋Š” ๋ฐ์—๋Š” 2๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค. ํ•จ์ˆ˜๋กœ ์ •์˜ (ES5 ๋ฌธ๋ฒ•) function Introduce(name, age, favorite) { // ์ธ์Šคํ„ด์Šค ๋งŒ๋“ค์–ด์งˆ ๋•Œ ์‹คํ–‰๋˜๋Š” ์ฝ”๋“œ } class ํ‚ค์›Œ๋“œ๋กœ ์ •์˜ (ES6 ๋ฌธ๋ฒ•) class Introduce { constructor(name, age, favorite) { // ์ธ์Šคํ„ด์Šค๊ฐ€ ๋งŒ๋“ค์–ด์งˆ ๋•Œ ์‹คํ–‰๋˜๋Š” ์ฝ”๋“œ } } ์—ฌ๊ธฐ์„œ constructor๋Š” ํด๋ž˜์Šค๊ฐ€ ์ธ์Šคํ„ด์Šค ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•  ๋•Œ ๊ฐ์ฒด๋ฅผ ์ดˆ๊ธฐํ™”ํ•˜๋Š” ๋ฉ”์†Œ๋“œ์ด๋‹ค. constructor ๋ฉ”์†Œ๋“œ๋ฅผ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์‚ฌ์šฉํ•œ๋‹ค๋ฉด, cla..

article thumbnail
[S2U2] JavaScript ๊ฐ์ฒด ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ

๊ฐ์ฒด ์ง€ํ–ฅ ๊ฐ์ฒด ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์ด๋ž€? ํ•˜๋‚˜์˜ ์ฒญ์‚ฌ์ง„์„ ๋งŒ๋“ค๊ณ  ๊ทธ ์ฒญ์‚ฌ์ง„์„ ๋ฐ”ํƒ•์œผ๋กœ, ์ฆ‰ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ๋Š” class๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ํ•˜๋Š” ํ•˜๋‚˜์˜ ๊ฐ์ฒด, ์ฆ‰ instance๋ฅผ ๋งŒ๋“œ๋Š” ํ”„๋กœ๊ทธ๋ž˜๋ฐ ํŒจํ„ด์„ ์˜๋ฏธํ•œ๋‹ค. โœ๏ธ ํด๋ž˜์Šค์™€ ์ธ์Šคํ„ด์Šค ํด๋ž˜์Šค๋Š” ์†์„ฑ๊ณผ ๋ฉ”์†Œ๋“œ๋ฅผ ์ •์˜ํ•˜๋Š” ๊ณต๊ฐ„์ด๊ณ  ์ธ์Šคํ„ด์Šค๋Š” ํด๋ž˜์Šค์—์„œ ์ •์˜๋œ ์ •๋ณด๋“œ๋ฅผ ๊ฐ€์ ธ์™€ ์ด์šฉํ•˜๋Š” ๊ฐ์ฒด์ด๋‹ค. ์†์„ฑ์€ ํด๋ž˜์Šค์— ํฌํ•จ๋˜๋Š” ๋ณ€์ˆ˜๋ฅผ ์˜๋ฏธํ•˜๊ณ , ๋ฉ”์†Œ๋“œ๋Š” ํด๋ž˜์Šค์— ํฌํ•จ๋˜๋Š” ํ•จ์ˆ˜๋ฅผ ์˜๋ฏธํ•œ๋‹ค. ํด๋ž˜์Šค๋ฅผ ์ •์˜ํ•˜๋Š” ๋ฐ์—๋Š” 2๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค. ํ•จ์ˆ˜๋กœ ์ •์˜ (ES5 ๋ฌธ๋ฒ•) function Introduce(name, age, favorite) { // ์ธ์Šคํ„ด์Šค ๋งŒ๋“ค์–ด์งˆ ๋•Œ ์‹คํ–‰๋˜๋Š” ์ฝ”๋“œ } class ํ‚ค์›Œ๋“œ๋กœ ์ •์˜ (ES6 ๋ฌธ๋ฒ•) class Introduce { constructor(..

profile on loading

Loading...