类装饰器

  1. function age(args:number = 0) {
  2. return function (target:Function):void {
  3. target.prototype.age = args;
  4. }
  5. }
  6. @age(2)
  7. class Hello{
  8. public name:string;;
  9. constructor(){
  10. this.name = 'name';
  11. }
  12. }
  13. const hello1 = new Hello();
  14. console.log(hello1.name);
  15. console.log(hello1.age); // 2