이론 (Front-end)/TypeScript

[TypeScript] Static 키워드

이우열 2023. 12. 27. 18:58
728x90

✅ Static

클래스를 통해 인스턴스를 생성할 필요 없이, 클래스의 속성 또는 메소드를 사용하는 방식

 

class Player {
    static firstName: string = "GilDong";
    static hello() {
        return "hello"
    }
}

Player.firstName;
Player.hello();

 

위의 예시처럼 속성과 메소드static 키워드를 붙이면 클래스의 인스턴스를 생성하지 않고

속성과 메소드를 사용할 수 있습니다.

 

console.log 출력 예시

 

728x90