
여러 호출 방식에 따라 정의가 달라지는 실행 함수의 호출자이다.
(너무 많고 다양한 의미로 부르기에, 내가 이해할 수 있는 언어로 작성했다.)
this 키워드의 상태는 크게 네 가지의 방식에 따라 나뉘는데,
함수 호출, 메소드 호출, 객체 생성 함수, (apply, call, bind) 이다.
그 전에, 바인딩에 대해서 짧게 설명하고 넘어가자.
const func = function(){
const name = "1";
console.log(this);
console.log(this.name);
}
func(); // 출력 : window 객체, 빈 값
const o = {
prop: 55,
foo: function() {
return this.prop;
}
}
console.log(o.f()) // 출력 : 37
function getUserInfo(){
this.name = "김준표",
this.age = "26",
this.tall = "186"
}
const user = new getUserInfo();
console.log(user); // {name: "김준표", age: "26", tall: "186"}