[typescript]class readonly

Mon Mar 24

typescript

Author:Noritaka

Astro
class Person {
  readonly id: number = 32;
  constructor(public name: string, private age: number) {
    this.id = 31;
    this.name = "kygo"
    this.id = 30;
  }
  incrementAge() {
    this.age += 1;
  }
  greeting(this: Person) {
    console.log(`Hello! My name is ${this.name}. I am ${this.age} years old.`);
  }
}

let person2: Person;
const quill = new Person('Quill', 38);
quill.incrementAge();
quill.greeting();
console.log(quill.id);

typescript