[Classes] Static Properties & Methods
                                            
                                                
                                                
                                                
                                                
                                                
                                                 5093 단어  typescripttypescript
                    
class Person {
  private static CITY = "Seoul";
  public static hello() {
    console.log("안녕하세요", Person.CITY);
  }
}
const p1 = new Person();
Person.hello();
→ class로부터 만들어진 object 중 공통적으로 사용하고 싶은 데이터가 있을 경우 static 키워드 사용
데이터 공유
class Person {
  private static CITY = "Seoul";
  public hello() {
    console.log("안녕하세요", Person.CITY);
  }
  public change() {
    Person.CITY = "LA";
  }
}
const p1 = new Person();
p1.hello(); // 안녕하세요 Seoul
const p2 = new Person();
p2.hello();  // 안녕하세요 Seoul
p1.change();  // CITY를 LA로 변경
p2.hello();  // 안녕하세요 LA
Author And Source
이 문제에 관하여([Classes] Static Properties & Methods), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@plutoin/Classes-Static-Properties-Methods저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)