강의

멘토링

커뮤니티

인프런 커뮤니티 질문&답변

흙먹는아기님의 프로필 이미지
흙먹는아기

작성한 질문수

자바스크립트 중고급: 엔진 핵심

7. prototype 프로퍼티 공유 시점

원본 생성자함수의 prototype안 메소드를 삭제해도 인스턴스에 할당된 메소드는 이와관계없이 동작이되는건가요?

작성

·

61

1

삭제된 글입니다

답변 1

0

function Book(){
  this.point = 100;
}

Book.prototype = {
  constructor: Book,
  getPoint: function(){
    return this.point;
  },
  add: function(){
    console.log(12312331)
  }
}

var obj = new Book();

console.log(obj.getPoint())
// 100 이 호출되고
function Book(){
  this.point = 100;
}


var obj = new Book();

Book.prototype = {
  constructor: Book,
  getPoint: function(){
    return this.point;
  },
  add: function(){
    console.log(12312331)
  }
}

console.log(obj.getPoint())


//Uncaught TypeError: obj.getPoint is not a function 이렇게 뜨네요
getPoint를 호출한 시점에 Book.prototype을 참조한다고 이해했는데 위치에 따라 왜 다르게 나오는걸까요 ..?ㅠ
흙먹는아기님의 프로필 이미지
흙먹는아기

작성한 질문수

질문하기