流浪のwolf

卷帝

导航

nextjs 的函数,参数,属性装饰器的使用

// 属性装饰器
const doc1:PropertyDecorator = (target:any,val: string | symbol) => {
    console.log(target);
    console.log(val);
    val = "覆盖";
}
// 方法装饰器
const doc2: MethodDecorator = (target:any,val: string | symbol,desc:any) => {
    console.log(target,val,desc);
}
// 参数装饰器
const doc3: ParameterDecorator = (target:any,val: string | symbol,index:any) => {
    console.log(target,val,index);
}
class Zlx{
    @doc1
    public name : string;
    constructor(){
        this.name = "小龙";
    }
    @doc2
    getName(name:string,@doc3 age:number){

    }
}

const z1 = new Zlx();
console.log(z1.name);

 

posted on 2024-04-03 21:19  流浪のwolf  阅读(13)  评论(0编辑  收藏  举报