❗️해당 게시글은 공부한 내용을 정리한 글입니다.
❗️잘못된 내용이 있을 수 있습니다.
❗️혹시 잘못된 내용이 있다면 댓글로 피드백 부탁드리겠습니다! 🙇♂️
call 메서드
Function.prototype.call(thisArg[, arg1[, arg2[, ...]]])
call 메서드로 함수를 호출할 때 첫 번째 인자로 this를 바인딩 할 수 있다.
apply 메서드
Function.prototype.apply(thisArg[, argsArray])
apply 메서드는 call 메서드와 기능적으로 완전히 동일하다.
인자를 받는 방법에만 차이가 있다.
bind 메서드
Function.prototype.bind(thisArg[, arg1[, arg2[, ...]]])
bind 메서드는 넘겨 받은 this 및 인수들을 바탕으로 새로운 함수를 반환하는 메서드이다.(call처럼 즉시 호출하지 않음)
const func = function (a, b, c, d) {
console.log(this, a, b, c, d);
};
const bindFunc = func.bind({ x: 1 }, 4, 5);
console.log(func.name); // func
console.log(bindFunc.name); // bound func