https://m.blog.naver.com/pjt3591oo/222120496022
[typescript] ํ์ ์คํฌ๋ฆฝํธ ๋ฐ์ฝ๋ ์ดํฐ 1ํธ - ๋ฐ์ฝ๋ ์ดํฐ 4๊ฐ์ง ๊ธฐ๋ณธ๊ตฌ์กฐ ์์๋ณด๊ธฐ
์๋ ํ์ธ์. ๋ฉ๊ฐ์ ๋๋ค ์ด๋ฒ๊ธ์์๋ ํ์ ์คํฌ๋ฆฝํธ์์ ์ง์ํ๋ ๋ฐ์ฝ๋ ์ดํฐ์ ๊ธฐ๋ณธ๊ตฌ์กฐ๋ฅผ ์์๋ณด๊ฒ ์ต๋๋ค...
blog.naver.com
https://sleepybird.tistory.com/158
[199์ผ์ฐจ]ํ์ ์คํฌ๋ฆฝํธ ๋ฐ์ฝ๋ ์ดํฐ
Reference ๐๊ณต์๋ฌธ์ ํ์ ์คํฌ๋ฆฝํธ ๋ฐ์ฝ๋ ์ดํฐ ๋ค์คํธ๋ ์ต๊ทค๋ฌ๊ฐ์ ํ๋ ์์ํฌ๋ฅผ ๋ง์ฃผํ๋ค๋ณด๋ฉด ์ฌ์ฌ์น์๊ฒ ๋ณผ์์๋๋ ์์ด ์๋ค. ๋ฐ๋ก ์ด ๊ณจ๋ฑ ์ด๊ฐ ๋ถ์ด์ง '๋ฐ์ฝ๋ ์ดํฐ' ๋ผ๊ณ ๋ถ๋ฆฌ๋ ๋ ์์ด๋ค
sleepybird.tistory.com
๊ณจ๋ฑ
์ด๊ฐ ๋ถ์ด์ง '๋ฐ์ฝ๋ ์ดํฐ' ๋ผ๊ณ ๋ถ๋ฆฌ๋ ๋
์
ํ์
์คํฌ๋ฆฝํธ์๋ง ์๋๊ฑด ์๋๊ณ , ์๋ฐ์คํฌ๋ฆฝํธ์๋ ์๋ ๊ธฐ๋ฅ์ด์ง๋ง ์ ์๊ธฐ๋ฅ์ด์๋,
ํ์คํ ์ ์ฐจ๋ฅผ ์งํ์ค์ธ ๊ธฐ๋ฅ
ํ์
์คํฌ๋ฆฝํธ์์ ์ด ๊ธฐ๋ฅ์ ์ ๊ณต์ ํ๊ณ , ํ์
์คํฌ๋ฆฝํธ๋ฅผ ๊ธฐ๋ฐ์ผ๋กํ๋ ํ๋ ์์ํฌ์์๋
์ด ๊ธฐ๋ฅ์ ์ฌ์ฉ.
๋ฐ์ฝ๋ ์ดํฐ๋ ํด๋์ค, ์์ฑ, ๋ฉ์๋, ๋งค๊ฐ๋ณ์ ์์ ๋ถ์ผ ์ ์๋ ํจ์์ด๋ค.
์์ 1
function hello(constructFn: Function) {
console.log(constructFn);
}
@hello
class Person {
}
์ถ๋ ฅ
class Person {
}
์์ 2
function hello(constructFn: Function) {
console.log(constructFn);
console.log('Hi!');
}
function bye(constructFn: Function) {
console.log(constructFn);
console.log('bye!');
}
function helloFactory(show: boolean) {
if (show) {
return hello;
} else {
return bye;
}
}
@helloFactory(true)
class Person {
}
์ถ๋ ฅ
class Person {
}
Hi!
์์ 3
function hello(constructFn: Function) {
console.log(constructFn);
console.log('Hi!');
}
function bye(constructFn: Function) {
console.log(constructFn);
console.log('bye!');
}
function helloFactory(show: boolean) {
if (show) {
return hello;
} else {
return bye;
}
}
@helloFactory(false)
class Person {
}
์ถ๋ ฅ
class Person {
}
bye!
'TypeScript > ํ์ ์คํฌ๋ฆฝํธ TypeScript' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ์ ์คํฌ๋ฆฝํธ ์์ ] ์ ๊ท ํํ์ regex, ์ ํ๋ธ์์ id๊ฐ๋ง ์ถ์ถํด์ EMBED ํด๋ณด๊ธฐ (0) | 2022.05.21 |
---|---|
[ํ์ ์คํฌ๋ฆฝํธ] declare namespace (0) | 2022.05.06 |
[ํ์ ์คํฌ๋ฆฝํธ] ์ ์ฉํ ์ต์คํ ์ , Auto import (0) | 2022.05.05 |
[ํ์ ์คํฌ๋ฆฝํธ] .d.ts ์ ๋ํ ์ดํด (0) | 2022.05.04 |
[ํ์ ์คํฌ๋ฆฝํธ] ! Non-null assertion operator (0) | 2022.05.02 |