Learn JavaScript
❯ functions.call_apply_bind

call, apply & bind (this Control) in JavaScript

$concept

Every function carries three methods for explicit receiver control: call (invoke with this plus comma args: f.call(obj, 1, 2)), apply (same with array args: f.apply(obj, [1, 2])), and bind (return a new function permanently bound: const g = f.bind(obj)). Together they borrow methods across objects, forward variadic arguments, and lock callbacks to receivers.

Classic uses: Array.prototype.slice.call(arguments) (pre-rest array conversion), Math.max.apply(null, arr) (pre-spread maximum), and bound event handlers (this.onClick = this.onClick.bind(this)) before arrow-function class fields took over.

$how it works
1

call: comma arguments

f.call(obj, 1, 2) runs f with this=obj β€” borrowing methods onto foreign objects.

2

apply: array arguments

f.apply(obj, argsArray) spreads dynamically β€” variadic forwarding before rest/spread syntax.

3

bind: permanent binding

const g = f.bind(obj, 1) locks receiver (and leading args), returning a callable for later.

4

Arrows ignore all three

call/apply/bind cannot rebind arrow functions (lexical this wins) β€” use function expressions where rebinding matters.

$example
function greet(greeting) {
return greeting + ", " + this.name;
}
let user = { name: "Ada" };
console.log(greet.call(user, "hi"));
let bound = greet.bind(user);
console.log(bound("yo"));
Output
hi, Ada
yo, Ada
1greet.call(user, "hi") runs greet with this=user β€” borrowing without any method relationship.
2bind locks user in, returning a one-argument function for later calls.
3Both print through the borrowed receiver β€” explicit this control twice over.
$use cases
Borrowing array methods for array-likes (pre-spread idioms)
Binding callbacks to component instances in legacy React/classes
Partial application via bind's leading-argument locking
Forwarding dynamic argument lists with apply

Recommended resourcesAffiliate links Β· may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice β€” pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from β€” great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in JavaScript yourself β€” building beats watching.