Skip to content
Tutorials Center
My learning

Topics

JavaScript Reference ยท Function

Function.prototype.call()

Reference for JavaScript Function.prototype.call(): run a function immediately with a chosen this value and separate arguments, with practical uses.

call() invokes a function right away with an explicit this value and with arguments passed one by one. It lets you borrow a method for an object that does not own it, or run a plain function as if it were a method.

It is the immediate cousin of bind() (which returns a new function) and of apply() (which takes the arguments as an array).

JavaScript
fn.call(thisArg, arg1, arg2);

Try it

JS Choosing this

Press Run (or Ctrl + Enter) to see the console output here.

No output.

JS Borrowing methods

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Syntax

JavaScript
fn.call(thisArg)
fn.call(thisArg, arg1, arg2, /* ..., */ argN)
Name Description
thisArg The value to use as this inside the call.
arg1, ..., argN Arguments passed to the function, in order.

Return value: whatever the function returns.

Exceptions: a TypeError if call is used on a non-function. Any error thrown by the function itself passes through.

Usage notes

  • this in strict mode is exactly thisArg, even a primitive or undefined. In sloppy mode, null and undefined become the global object and primitives are wrapped in objects.
  • Arrow functions ignore thisArg. Their this is fixed where they are written; only the arguments are passed.
  • Borrowing array methods for array-likes such as arguments, DOM collections or { length } objects was common. Today Array.from() or spread is usually clearer.
  • Calling a parent method in old-style inheritance: Parent.call(this, name) runs a constructor on the current object. Classes use super() instead.
  • Safe method access: Object.prototype.hasOwnProperty.call(obj, key) works even if obj defines its own hasOwnProperty or has no prototype.
  • Spread instead of apply(). When you have an array of arguments, fn.call(ctx, ...args) replaces fn.apply(ctx, args).
  • Performance is comparable to a normal call in modern engines.

Browser support

call() is available in every browser and JavaScript runtime.