메서드로서 호출
by hyunkikim
JavaScript
function whatsMyContext() {
return this
}
console.log(whatsMyContext() === window) // ?
// 1. whatsMyContext 함수를 참조
const getMythis = whatsMyContext
console.log(getMythis() === window) // ?
// 2. 객체의 메서드로 참조해서 호출
const obj = {
getMyThis: whatsMyContext
}
console.log(obj.getMyThis() === obj) // ?
const obj2 = {
getMyThis: whatsMyContext
}
console.log(obj2.getMyThis() === obj) // ?
console.log(obj2.getMyThis() === obj2) // ?