카테고리 없음

[TS] Class : readonly, static

L.Joey 2024. 3. 8. 01:48

readonly 으로 선언 된 것은 읽기전용

static 으로 선언 된 것은 클래스 명을 이용하여 호출가능

 

class Car {
     readonly name: string = "car";
     color: string;
     static wheels = 4;
     constructor(color: string, name: string){
        this.color = color;
        this.name = name;
     }
     start(){
        console.log('start');
        console.log(this.name);
        //console.log(this.wheels); //error
        console.log(Car.wheels)
     }
}