- ๋ฉํ ํ๋ก๊ทธ๋๋ฐ ํ๋ ๋ฐ ๋งค์ฐ ์ ์ฉํ๊ฒ ์ฌ์ฉ ๋จ
- ๋ฉํ ํ๋ก๊ทธ๋๋ฐ์ด๋?
- end user๊ฐ ํ์ด์ง๋ฅผ ๋ฐฉ๋ฌธํ๋๋ฐ, ๋ณดํต ๊ณง๋ฐ๋ก ์ํฅ์ ์ฃผ๊ธฐ์ ๋ฐ์ฝ๋ ์ดํฐ๋ฅผ ์ฌ์ฉํ์ง ์์
- ๋์ ์ ์ฝ๋๋ฅผ ์ฐ๋ ๋ฐ ์ ํฉํ๋๋ก ๋ง๋ค์ด ๋ฐ์ฝ๋ ์ดํฐ๋ฅผ ๋ค๋ฅธ ๊ฐ๋ฐ์๋ค์ด ์ฌ์ฉํ๊ธฐ ์ฝ๊ฒ ํจ
- ๋ฐ์ฝ๋ ์ดํฐ๋ ์ค์ฒดํ๋๊ธฐ ์ ํด๋์ค๊ฐ ์ ์๋ง ๋ผ๋ ์คํ ๋จ
function Logger(constructor: Function) {
console.log("Logging...");
console.log(constructor);
}
@Logger
class Person1 {
name = "Yum";
constructor() {
console.log("Creating person object...");
}
}
const pers = new Person1();
console.log(pers);
- ์์ ๊ฐ์ด ๋ฐ์ฝ๋ ์ดํฐ๋ฅผ ๋ง๋๋ ๋์ , ๋ฐ์ฝ๋ ์ดํฐ ํฉํ ๋ฆฌ(factory)๋ฅผ ์ ์ํ ์ ์์
๋ฐ์ฝ๋ ์ดํฐ ํฉํ ๋ฆฌ (factory)
function Logger(logString: string) {
return function (constructor: Function) {
console.log("Logging...");
console.log(constructor);
};
}
@Logger("LOGGING - PERSON")
class Person1 {
name = "Yum";
constructor() {
console.log("Creating person object...");
}
}
const pers = new Person1();
console.log(pers);
function Logger(logString: string) {
return function (constructor: Function) {
console.log("Logging...");
console.log(constructor);
};
}
function WithTemplate(template: string, hookId: string) {
return function (_: Function) {
const hookEl = document.getElementById(hookId);
if (hookEl) {
hookEl.innerHTML = template;
}
};
}
// @Logger("LOGGING - PERSON")
@WithTemplate("<h1> My Person Object <h2/>", "app")
class Person1 {
name = "Yum";
constructor() {
console.log("Creating person object...");
}
}
const pers = new Person1();
console.log(pers);LIST
'#1 Language ๐ > 1-3 Typescript' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| [Typescript] ์ ๋ค๋ฆญ Generic <T> (1) | 2023.12.23 |
|---|---|
| [Typescript] ๊ณ ๊ธ ํ์ (1) | 2023.12.23 |
| [Typescript] ํด๋์ค & ์ธํฐํ์ด์ค (1) | 2023.12.23 |
| [Typescript] ๊ตฌ์กฐ ๋ถํด (1) | 2023.12.23 |
| [Typescript] TypeScript ์ปดํ์ผ๋ฌ(๋ฐ ๊ตฌ์ฑ) (1) | 2023.12.23 |