함수 호출 방식과 this 바인딩
const foo = function () {
console.dir(this);
};
// 1. 함수 호출
foo();
// 2. 메서드 호출
const obj = { foo: foo };
obj.foo();
// 3. 생성자 함수 호출
const instance = new foo();
// 4. apply, call, bind 호출
const bar = { name: "bar" };
foo.call(bar);
foo.apply(bar);
foo.bind(bar);🌳 1. 함수 호출

🌳 2. 메서드 호출


🌳 3. 생성자 함수 호출
생성자 함수 동작 방식

객체 리터럴 방식과 생성자 함수 방식의 차이
생성자 함수에 new를 붙이지 않고 호출할 경우
🌳 4. apply, call, bind 호출
명시적으로 this를 바인딩해줘야 하는 예시
출처
Last updated