1.일반 함수에서 호출시 (전역 객체)
console.log(this === window);
a = "KJM";
console.log(window.a);
function x(){
return this;
}
x() === window;
2.메서드 에서 호출시(호출한 객체)
let fruit = {
favorite: "apple",
lestFaverite: "orange",
favoriteFruit() {
console.log(this.favorite + "is my favorite fruit")
}
}
fruit.favoriteFruit();
3. 생성자 함수에서 호출시(생성자 함수가 생성할 객체)
function Fruit() {
this.favorite = "apple",
this.lestFaverite = "orange",
this.start = function() {
console.log(this.favorite + "is my favorite fruit")
}
}
let Fruit = new fruit();
console.log(person1);