1.类装饰器
参数为修饰的类
如果返回一个类,则实例化的时候,使用的是返回的这个类
2.方法装饰器
修饰非静态方法时参数为 类的prototype 函数额名称 函数的描述符
修饰静态方法时参数为 类的 constructor 函数额名称 函数的描述符
3.get和set装饰器不能同时使用
4.属性装饰器
修饰静态(static)属性时,传入class 和属性名,非静态时传入原型和属性名
可以返回一个PropertyDescriptor类型的对象实现属性描述符的功能
function nameDsce(prototype: any, argName: any): any {
let desc: PropertyDescriptor = {
writable: false
}
return desc
}
5:参数装饰器
//类/原型,函数名,参数的下标
function paramsDeco(proto: any, method: string, paramIndex: number) {
console.log(method, paramIndex) //getName 1
}
class Person {
getName(name: string, @paramsDeco age: number) {
console.log(name)
}
}
总结:
类的内部使用装饰器时,只要是静态属性,第一个参数都是类,否则就是原型