typescript方法参数装饰器
dearweb
发布:2021-08-01 17:25:56阅读:
在使用参数装饰器为类的原型增加一些元素数据的时候,传入下列3个参数;对于静态成员来说类的构造函数,对于实例成员是类的原型对象;方法的名称;参数在函数参数列表中的索引。
function logParams(params:any){
return function(target:any,paramsName:any,parameIndex:any){
console.log(target,paramsName,parameIndex)
console.log(params)
}
}
class HttpClient {
public url:any| undefined
constructor() {
}
getData(@logParams('xxxxxxx')uuid:any){
console.log('我是get方法')
console.log(uuid);
}
}
let http =new HttpClient();
http.getData(123456)
// 打印顺序
{getData: ƒ, constructor: ƒ}
"getData"
0
xxxxxxx
我是get方法
123456小礼物走一波,支持作者
赏还没有人赞赏,支持一波吧