CKTIS / JavaScript
Function.prototype.apply — call with an argument list
Function.prototype.apply calls a function with a supplied this value and arguments read from an array-like object. It lets you pass a prepared list instead of writing each argument separately.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
fn.apply(thisArg, argArray)Function.prototype.apply calls a function immediately and returns its result. In fn.apply(thisArg, argArray), thisArg specifies the supplied this value, while argArray supplies positional arguments. By comparison, fn.call(thisArg, a, b) accepts arguments individually.
argArray can be an array or an array-like object with length and indexed properties such as 0 and 1. Passing null, passing undefined, or omitting this parameter means no arguments. Values are read by index, not through an iterator; a missing index usually yields undefined, but may be inherited from the prototype. Any other primitive value, including a string, causes a TypeError.
apply passes thisArg unchanged, but an ordinary non-strict function replaces null and undefined with its global this value and boxes other primitive values into objects. An ordinary strict function preserves the supplied value. Arrow functions and functions bound with bind ignore this choice of this.
In the example, args is not an array: its two elements become parameters a and b, and context becomes this. The result is 15. Attempting to use apply with a receiver that is not callable causes a TypeError.
Examples
function total(a, b) {
"use strict";
return this.base + a + b;
}
const context = { base: 10 };
const args = { 0: 2, 1: 3, length: 2 };
console.log(total.apply(context, args));Result
15
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.