📜  typescript readonly - TypeScript 代码示例

📅  最后修改于: 2022-03-11 14:48:31.694000             🧑  作者: Mango

代码示例2
class Octopus {  readonly name: string;  readonly numberOfLegs: number = 8;
  constructor(theName: string) {    this.name = theName;  }}
let dad = new Octopus("Man with the 8 strong legs");dad.name = "Man with the 3-piece suit";Cannot assign to 'name' because it is a read-only property.2540Cannot assign to 'name' because it is a read-only property.Try