call, apply, bind — how do you set this?
Answer out loud or in your head first, then compare.
Answer
call calls the function with arguments passed separately, apply with a list of arguments, and bind creates a new function with a fixed this and, optionally, some of the arguments.
JavaScript
function greet(prefix) { return `${prefix} ${this.name}`; }
const user = { name: 'Anna' };
greet.call(user, 'Hi'); // Hi Anna
greet.apply(user, ['Hi']); // Hi Anna
const hello = greet.bind(user, 'Hi');
hello(); // Hi AnnaPitfall: an arrow function takes this lexically. Call/apply/bind won't change its this the way they do for a regular function. When removing a listener I have to pass the same function reference, not another bind.
How did it go? Be honest — “Not yet” puts the question on your review list.