首页 > 其他分享 >[Typescript 4.9] Auto-Accessors in Classes

[Typescript 4.9] Auto-Accessors in Classes

时间:2022-11-30 15:36:40浏览次数:50  
标签:Typescript string Auto 4.9 Classes Accessors name

Typescript 4.9 supports an upcoming feature: Auto-accessors:

class Person {
  accessor name: string
  constructor(name: string) {
    this.name = name
  }
}

 

Under the covers, it is a "getter' and "setter" with an unreachable private property.

class Person {
   #__name: string
  constructor(name: string) {
    this.name = name
  }
    get name() {
     return this.#__name
    }

    set name(name: string) {
     this.#__name = name
    }
}

 

标签:Typescript,string,Auto,4.9,Classes,Accessors,name
From: https://www.cnblogs.com/Answer1215/p/16938576.html

相关文章