decorator

作者: 陶六六 | 来源:发表于2018-08-30 19:22 被阅读0次

    装饰器

    1. 装饰类对象
      @test
      class A{}
      function test(target){//类对象装饰器函数target指向类对象
          target.a = 1//修改类的静态属性和方法
          target.prototype.a =2//修改类的原型对象的属性和方法
      }
       A.a//1
       new A().a//2
      
    2. 装饰类的方法
       class A{
           @test
           a(){}
       }
       function test(target,name,descriptor){
           //target:类的原型对象 A.prototype
           // name:修改的属性名  'a'
           // descriptor:属性的描述对象 Object.getOwnPropertyDescriptor(A.prototype,'a') 
       }
      

    相关文章

      网友评论

          本文标题:decorator

          本文链接:https://www.haomeiwen.com/subject/ojidwftx.html