装饰器
TypeScript 的语法,试验性功能,在 tsconfig.josn
设置:"experimentalDecorators": true
// 类装饰器
function MyClassDecorator(constructor: Function) {
// constructor:类的构造函数
}
// 方法装饰器
function MyMethodDecorator(target: Object, propertyKey: string, descriptor: PropertyDescriptor) {
// target:原型对象/构造函数(方法归属)
// propertyKey:方法名
// descriptor:方法的属性描述符,descriptor.value 可以拿到原函数
}
// 属性装饰器
function MyPropertyDecorator(target: Object, propertyKey: string) {
// Object:原型对象/构造函数(属性归属)
// propertyKey:属性名
}