call, apply & bind (this Control) in JavaScript
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.
call: comma arguments
f.call(obj, 1, 2) runs f with this=obj β borrowing methods onto foreign objects.
apply: array arguments
f.apply(obj, argsArray) spreads dynamically β variadic forwarding before rest/spread syntax.
bind: permanent binding
const g = f.bind(obj, 1) locks receiver (and leading args), returning a callable for later.
Arrows ignore all three
call/apply/bind cannot rebind arrow functions (lexical this wins) β use function expressions where rebinding matters.
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"));Recommended resourcesAffiliate links Β· may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in JavaScript yourself β building beats watching.