인프런 커뮤니티 질문&답변
this 질문
작성
·
170
0
var relationship1 = {
name: "zero",
friends: ["nero", "hero", "xero"],
logFriends: function() {
var that = this;
this.friends.forEach(function(friend) {
console.log(that.name, friend);
});
}
};
relationship1.logFriends();
여기서 this를 that에 대입을 하는 이유가 뭔가요?
logFriends 안에서 콘솔로그로 this를 보니까 Object[global] ~~ 이런게 뜨던데 그럼 this를 that에 대입해도 똑같은 값이 대입되어야 하지 않나요?
그런데 that에 대입을 하고 콘솔로그해보면 relationship1의 객체가 나오네요..
이유가 궁금합니다.
답변 1
1





