강의노트 - 4

김희목·2024년 7월 17일
0

패스트캠퍼스

목록 보기
12/53

Getter, Setter

Getter = 어떤 값을 얻는 용도의 메소드

class User {
  constructor(first, last) {
    this.firstName = first;
    this.lastName = last;
  }
  get fullName() {
    return `${this.firstName} ${this.lastName}`;
  }
}

const heropy = new User("Heropy", "Park");
console.log(heropy.fullName);

Setter = 어떤 값을 지정하는 용도의 메소드

class User {
  constructor(first, last) {
    this.firstName = first;
    this.lastName = last;
  }
  get fullName() {
    return `${this.firstName} ${this.lastName}`;
  }
  set fullName(value) {
    console.log(value)
  }
}

const heropy = new User("Heropy", "Park");
console.log(heropy.fullName);

heropy.fullName = 'Neo Anderson'

prototype 메소드 / 정적 메소드 차이점

prototype 메소드는 일반 인스턴스에서 사용이 가능하고
정적 메소드는 인스턴스에서는 사용 불가능하고 클래스 자체에서 사용가능하다.

0개의 댓글