作用于方法及构造函数的参数,在参数的左边声明
function decorator ( target: Function , name: string, index: number ) {}
- 参数说明
- target:静态成员:类的构造函数;实例成员:类的原型对象
- name:方法的成员名称
- index:在所有形参中的索引
- 参数装饰器的返回值会被忽略
实例
function decorator () {
return function ( target: Function , name: string, index: number ) {
console.log(`this params is ${ index + 1 } of ${ name }`)
}
}
class ClassName {
method( @decorator() params: number ): void { }
}