0
点赞
收藏
分享

微信扫一扫

ts重点学习119-方法的装饰器笔记


export default {}


// 普通方法: target对应的就是 prototype
// 静态方法: target对应的就是 类的构造函数
function getNameDecorator(target: any, key: string, desciptor: PropertyDescriptor) {
// console.log(target);
// console.log(key);
// console.log(desciptor);

// desciptor.writable = false;

desciptor.value = function() {
return "descrator"
}
}



class Test {
name: string = "郑合惠子"
constructor(name: string) {
this.name = name
}
@getNameDecorator
getName() {
return this.name
}
// @getNameDecorator
static show():void {
console.log("Hello Show");

}
}


let t = new Test("aaa")
// t.getName = () => {
// return "Hello 张雪迎"
// }
console.log(t.getName());

举报

相关推荐

0 条评论