Full answer
Every function has these three methods, and all of them exist to control this explicitly.
fn.call(thisArg, a, b) calls fn right away. The first argument becomes this, and the remaining arguments are passed in the normal way.
fn.apply(thisArg, [a, b]) also calls fn right away, but passes the arguments as one array or array-like object. Today, spread syntax fn.call(thisArg, ...list) does the same job, so apply is mostly seen in older code.
fn.bind(thisArg, a) does not call anything. It returns a new function whose this is fixed. Any extra arguments passed to bind are fixed at the front, which is called partial application. The new function can be called later, passed as a callback, or used as an event handler. A bound function ignores later attempts to change its this with call, apply, or another bind, though it still works with new.
Typical uses are borrowing methods from another object, fixing a lost this in a callback, and creating specialized functions from a general one.
None of them affects arrow functions, because arrow functions have no this of their own.
'use strict';
function introduce(greeting, punctuation) {
return `${greeting}, I am ${this.name}${punctuation}`;
}
const maya = { name: 'Maya' };
const arjun = { name: 'Arjun' };
console.log(introduce.call(maya, 'Hello', '!'));
console.log(introduce.apply(arjun, ['Hi', '.']));
const mayaHello = introduce.bind(maya, 'Hello');
console.log(mayaHello('?'));
console.log(mayaHello.call(arjun, '!'));
const marks = [72, 91, 64];
console.log(Math.max.apply(null, marks), Math.max(...marks));
const arrayLike = { 0: 'a', 1: 'b', length: 2 };
console.log(Array.prototype.map.call(arrayLike, (x) => x.toUpperCase()));
const counter = {
count: 0,
increase() {
this.count += 1;
return this.count;
},
};
const loose = counter.increase;
const fixed = counter.increase.bind(counter);
try {
loose();
} catch (error) {
console.log('lost this:', error.name);
}
console.log(fixed(), fixed());Run with Node.js v24.22.1 as js-15.js; two runs gave identical output. Output: Hello, I am Maya! Hi, I am Arjun. Hello, I am Maya? Hello, I am Maya! 91 91 [ 'A', 'B' ] lost this: TypeError 1 2
Key points
- call and apply invoke the function immediately; bind returns a new function.
- call takes arguments one by one; apply takes an array.
- bind can pre-fill leading arguments (partial application).
- A bound function keeps its this even if called with call or apply later.
- Arrow functions ignore all three for this.
Common mistakes
- Thinking bind calls the function.
- Passing an array to call and getting the whole array as the first argument.
- Trying to rebind a bound function to a new object and expecting it to work.
- Using bind in a render path or a loop and creating a new function on every call when one stable reference would do.
Follow-ups
- How would you write your own bind function?
- What happens when a bound function is used with new?
- How do you borrow a method from Array.prototype for the arguments object?
Tips
- Give a one-line summary for each, then show a single function used with all three.
- Mention partial application as a second use of bind.
- If asked to implement bind, remember to merge pre-filled arguments with later ones.