This
const cat = {
name:'Blue Streele',
color:'grey',
breed:'scottish fold',
meow(){
console.log("meow")
}
}
cat.meow();
const cat = {
name:'Blue Streele',
color:'grey',
breed:'scottish fold',
meow(){
console.log(`${cat.name}`)
console.log(`${this.name}`)
}
}
cat.meow();
const meow2 = cat.meow;
meow2();
console.log(cat.meow)
console.log(meow2)
cat.meow의 this는 cat 오브젝트를 가르키고
meow2의 this는 cat 오브젝트를 가리키지 않는다.
this를 콘솔로 찍어보면
cat.meow의 this는 cat 오브젝트를 반환해주고
meow의 this는 window객체를 반환해준다.
![](https://velog.velcdn.com/images/dyddnjs0982/post/aa9741b0-6ec9-4d3b-b5fa-cbb6ab0105e0/image.png)
meow2는 cat.meow를 할당했지만 호출할 때 일반함수임
일반함수의 this는 window객체를 가르킴