Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

JS Puzzles · Const

this binding

JavaScript’s this for regular functions comes from the call form, not the definition. Use bind to create a callable function with a fixed this and optional initial arguments.

How it works

For regular functions, this is selected when the function is called. Calling through object.method() makes the object the receiver; extracting the method removes that receiver, while bind creates a callable function with a fixed this. Arrow functions instead use the surrounding lexical this.

Syntax

let bound = func.bind(context, [arg1], [arg2], ...);

Parameters

NameTypeDescription
contextanyThe object or value to use as this when the bound function is called.
argsany[]Optional leading arguments supplied to the original function before call-time arguments.

Returns

A bound variant of the original function with the selected this value and any preset leading arguments.

Key points

  • For ordinary functions, invocation style determines this; the function's definition location does not.
  • bind returns another callable function-like value rather than changing the original function.
  • Calling the bound result behaves like calling the original function with the selected context.
  • bind can preset both the receiver and leading arguments.
  • Use bind when an object method must be handed to a callback without losing its receiver.

Common mistakes

  • Passing a method as a callback can lose its object receiver, so this may no longer refer to the original object.
  • A bound function keeps the chosen context and initial arguments from the moment bind is called.

Example: Method calls and bind

const user = { name: "Ada", show() { return this.name; } };
const detached = user.show;
console.log(detached());
console.log(user.show());

const bound = user.show.bind(user);
console.log(bound());

The method call supplies the object as this; detaching the function loses that receiver, while bind preserves it.

When to use it

Preserve a method receiver

Passing an object method as a timer or callback.

Fix the calling context

Reusing one function with a chosen object context.

Partially apply arguments

Supplying arguments before a callback is invoked.

  • bind()
  • arrow functions
  • object methods
  • setTimeout

Source: Function Binding. Checked 2026-10-15.