0
点赞
收藏
分享

微信扫一扫

ts重点学习121-访问器的装饰器笔记


export default {}


function visitDecorator(target: any, key: string, descritor: PropertyDescriptor) {
// console.log(target);
// console.log(key);
// console.log(descritor);
descritor.writable = false
}


class Test {
private _name: string;
constructor(name: string) {
this._name = name
}
@visitDecorator
get name() {
// console.log("get");

return this._name
}

set name(newName: string) {
// console.log('set');

this._name = newName
}
}


const t = new Test("周雨彤")
// t.name = "钟楚曦"
console.log(t.name);

举报

相关推荐

0 条评论