CKTIS / JavaScript
Function.prototype.bind — binding this and leading arguments
Function.prototype.bind creates a new function with a stored this value and optional leading arguments. It does not invoke the original function; the result can be called later or passed as a callback.
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
const boundFn = fn.bind(thisArg, ...boundArgs);Function.prototype.bind returns a new function wrapping the original function. fn.bind(thisArg, ...boundArgs) stores thisArg and the boundArgs arguments without executing fn. On an ordinary call, bound arguments precede arguments supplied later — this is partial application.
During an ordinary call, neither call nor apply can replace the bound this. Another bind cannot change it either, although it can add arguments. An arrow function keeps its lexical this; bind can only bind its arguments. On an ordinary call, a non-strict target function still applies its usual this conversions: for example, it uses its realm’s global this value in place of null. In a browser, that value can be a WindowProxy rather than the underlying Window object.
Each bind creates a distinct function object, so keep the result if you later need the same reference. In the example, greet retains user as this and "Hello, " as its leading argument; even call with another object does not change the receiver.
If the original function is a constructor, the result can be called with new: the bound thisArg is then ignored, but bound arguments remain. A bound function has no own prototype property. Using Function.prototype.bind with a non-callable value throws TypeError.
Examples
"use strict";
function format(prefix, suffix) {
return `${prefix}${this.name}${suffix}`;
}
const user = { name: "Ada" };
const greet = format.bind(user, "Hello, ");
console.log(greet("!"));
console.log(greet.call({ name: "Lin" }, "?"));
console.log(greet === format.bind(user, "Hello, "));Result
Hello, Ada! Hello, Ada? false
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.