01 / Foundation
Understand the concept
call(), apply(), and bind() allow you to explicitly specify what 'this' should refer to when invoking a function.
These methods are widely used for function borrowing, event handlers, partial application, and interview questions.
02 / Implementation
Difference Between call, apply and bind
call-apply-bind.js
const person = {
name: "Subhasish",
};
function greet(city, country) {
console.log(
`Hello, I'm ${this.name} from ${city}, ${country}`
);
}
greet.call(person, "Bengaluru", "India");
greet.apply(person, ["Bengaluru", "India"]);
const greetPerson = greet.bind(person);
greetPerson("Bengaluru", "India");
04 / Interview