생성자(constructor)

생성자는 해당 클래스를 new 키워드를 사용해 인스턴스화 할때 자동으로 실행되는 특별한 메소드이다.

객체 초기화가 필요할 때: 생성자는 객체의 초기 상태를 설정하는 데 유용합니다. 객체의 프로퍼티에 기본값이 필요한 경우, 생성자 내에서 해당 프로퍼티를 초기화하면 됩니다.

constructor() {
        this.answer = [];
        this.isGameRunning = true;
}

생성자 내에서는 인스턴스 프로퍼티(멤버 변수)를 초기화할 때는 별도의 선언 없이 가능하기 때문에 let, var, const 등을 사용하지 않는다.

This line appears after every note.

Notes mentioning this note


Here are all the notes in this garden, along with their links, visualized as a graph.