인프런 커뮤니티 질문&답변
답변 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을 참조한다고 이해했는데 위치에 따라 왜 다르게 나오는걸까요 ..?ㅠ





