Dmytro Morar
JavaScript

Call Apply Bind

The methods call, apply, and bind are used for manual management of the context (this) of a function. They are available to all functions through the Function.prototype prototype.

call()

  • Calls the function immediately, passing this and arguments separated by commas.
  • Used when you need to call a function with a specific context right now.
func.call(thisArg, arg1, arg2, ...);

apply()

  • Similar to call(), but arguments are passed in the form of an array or pseudo-array.
  • Convenient when arguments are already in an array (for example, when using Math.max).
func.apply(thisArg, [arg1, arg2, ...]);

bind()

  • Does not call the function immediately, but returns a new function with a fixed this and (optionally) partially set arguments.
  • Used for deferred call or permanent context binding, for example, in event handlers.
const newFunc = func.bind(thisArg, arg1, arg2, ...);

Key Ideas

  • call and applyexecute the function immediately, with different ways of passing arguments.
  • binddoes not execute immediately, but returns a new function.
  • All three methods allow explicit management of the execution context (this).
  • Typical case: loss of context when passing a method as a callback.

On this page