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