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);

posted @ 2022-09-30 20:40  前端导师歌谣  阅读(45)  评论(0)    收藏  举报