装饰器
const watcher: ClassDecorator = (target: Function) => {
target.prototype.getName = <T>(name: T): T => {
return name
}
}
@watcher
class A {}
@watcher
class B {}
const a = new A();
(a as any).getName('Yang')
const hello = (age: number): ClassDecorator => {
return (target: Function) => {
target.prototype.getAge = () => {
return age
}
}
}
@hello(23)
class C {}
const c = new C()
@watcher
@hello(23)
class D {}
const d = new D()
const flag: PropertyDecorator = (...args) => {
console.log(args)
}
class E {
@flag
name: string
constructor(name: string) {
this.name = name
}
}
let e = new E('Yang')