깜놀하는 해므찌로

typescript static 정적 변수 활용 예시 본문

IT

typescript static 정적 변수 활용 예시

agnusdei1207 2023. 5. 25. 12:52
반응형
SMALL
class Car{
    #privat:number = 30;
    protected protect:string = "protected";
    readonly name:string = "Car"; // readonly 수정 불가능
    static staticName = "정적 변수";
    // color:string;
    constructor(public readonly color:string, name:string){
        this.color = color;
        this.name = name; // readonly 수정할 수 있도록 생성자에서 처리
    }
    start(){
        console.log("start");
        console.log(this.#privat); // private
        console.log(Car.staticName); // static 변수 사용 시 this 대신 class이름 사용
    }
}
반응형
LIST