装饰器
- 函数装饰器
MethodDecorator = <T>(target: Object, key: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | Void;
- 属性装饰器
PropertyDecorator = (target: Object, key: string) => void;
- class装饰器
ClassDecorator = <TFunction extends Function>(target: TFunction) => TFunction;
function funcDecorator(target, key, desc) {
console.log('funcDecorator_target', target);
console.log('funcDecorator_key', key);
console.log('funcDecorator_desc', desc);
return desc;
}
function propDecorator(target, key) {
console.log('propDecorator_target', target);
console.log('propDecorator_key', key);
}
function classDecorator(target) {
console.log('classDecorator_target', target);
return target;
}
@classDecorator
export class Test {
@propDecorator
public name: string = '';
@funcDecorator
public log(): void {}
}
以自己现在的努力程度,还没有资格和别人拼天赋

浙公网安备 33010602011771号