annotation / 어노테이션 / 데코레이터 /
Typescript 의 Decorator
function first() {
console.log("first(): factory evaluated");
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
console.log("first(): called");
};
}
function second() {
console.log("second(): factory evaluated");
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
console.log("second(): called");
};
}
class ExampleClass {
@first()
@second()
method() {}
}
first(): factory evaluated
second(): factory evaluated
second(): called
first(): called
build
아래처럼 --experimentalDecorators
를 해줘야 한다. 그렇지 않으면 error 가 생긴다.
tsc --experimentalDecorators
See Also
- 쿠…sal: [컴] 간단하게 typescript 시작하기 2
- 쿠…sal: [컴][TypeScript] typescript 기본 setup + visual studio code
- 쿠…sal: [컴][디자인패턴] Decorator Pattern
- 쿠…sal: [컴][파이썬] python decorator
댓글 없음:
댓글 쓰기