装饰器

  • 函数装饰器
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 {}
}

  

装饰器

上一篇:用户和组的管理


下一篇:爬虫部署-2,基于Docker的Scrapy+Scrapyd+Scrapydweb部署