function BlackDog(){
this.name = '흰둥이';
return {
name : '검둥이',
bark: function() {
console.log(this.name + ': 멍멍!');
}
}
}
const blackDog = new BlackDog();
blackDog.bark(); //검둥이: 멍멍!
일반함수는 자신이 종속된
객체
를 this로 가리킴검둥이: 멍멍!
function WhiteDog(){
this.name = '흰둥이';
return {
name : '검둥이',
bark: () => {
console.log(this.name + ': 멍멍');
}
}
}
const whiteDog = new WhiteDog();
whiteDog.bark(); //흰둥이: 멍멍!
화살표 함수는 자신이 종속된
인스턴스
의 this를 가르킴흰둥이: 멍멍!