이론 (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

'이론 (Front-end) > TypeScript' 카테고리의 다른 글

[TypeScript] Interface(인터페이스)  (0) 2023.12.27
[TypeScript] 타입 확장  (1) 2023.12.23
[TypeScript] Class(클래스)  (1) 2023.12.23
[TypeScript] 함수  (1) 2023.12.22
[TypeScript] 타입 시스템  (0) 2023.07.05