클래스 데코레이터
클래스 데코레이터
// Component 데코레이터
function Component(target:Function) {
// 프로토타입 객체 참조
let $ = target.prototype;
// 프로토타입 객체 확장
$.type = 'component';
$.version = '0.0.1';
}
// Component 데코레이터 사용
@Component
class TabsComponent {};
// TabsComponent 객체 인스턴스 생성
const tabs = new TabsComponent();
// 데코레이터로 설정된 프로토타입 확장은
// 타입 단언(Type Assertion) 필요
console.log((tabs as any).type); // 'component' 출력클래스 재정의
클래스 데코레이터 팩토리
참고
Last updated
