Back to blog
JavaScript

The Magic of this, call(), apply(), and bind() in JavaScript

May 14, 2026 3 min read

What Does this Mean?

this refers to:

Who is calling the function

The value of this changes depending on how the function is called.


this Inside Normal Functions

function show() {
  console.log(this);
}

show();


Browser Output

Window object


this Inside Objects

const user = {
  name: "Ali",

  greet() {
    console.log(this.name);
  }
};

user.greet();


Output

Ali


Why?

Because:

user called greet()

So:

this = user


Function → Caller Relationship

flowchart LR
    A[user object] --> B[greet()]
    B --> C[this = user]


What Is call()?

call() lets you manually set this.


Syntax

functionName.call(thisValue, arg1, arg2)


Example

const user1 = {
  name: "Ali"
};

const user2 = {
  name: "Sara"
};

function greet(city) {
  console.log(`${this.name} from ${city}`);
}

greet.call(user1, "Lucknow");
greet.call(user2, "Delhi");


Output

Ali from Lucknow
Sara from Delhi


What Happened?

call() changed the value of this.


What Is apply()?

apply() works like call() but arguments are passed as an array.


Syntax

functionName.apply(thisValue, [args])


Example

const user = {
  name: "Ahmed"
};

function introduce(city, country) {
  console.log(
    `${this.name} from ${city}, ${country}`
  );
}

introduce.apply(user, ["Lucknow", "India"]);


Output

Ahmed from Lucknow, India


call() vs apply()

MethodArgument Style
call()Separate arguments
apply()Array of arguments

What Is bind()?

bind() creates a new function with fixed this.

It does not execute immediately.


Syntax

const newFunction = oldFunction.bind(thisValue)


Example

const user = {
  name: "Ali"
};

function greet() {
  console.log(`Hello ${this.name}`);
}

const boundFunction = greet.bind(user);

boundFunction();


Output

Hello Ali


Important Difference

MethodExecutes Immediately?
call()Yes
apply()Yes
bind()No

bind() Visualization

flowchart LR
    A[greet()] --> B[bind(user)]
    B --> C[new function]


Method Borrowing With call()


Original Object

const person1 = {
  name: "Sara",

  greet() {
    console.log(`Hello ${this.name}`);
  }
};


Borrow Method

const person2 = {
  name: "Ali"
};

person1.greet.call(person2);


Output

Hello Ali


Using apply() With Array Arguments

function add(a, b) {
  console.log(a + b);
}

add.apply(null, [10, 20]);


Output

30


Storing Function With bind()

const user = {
  name: "Sara"
};

function greet() {
  console.log(this.name);
}

const savedFunction = greet.bind(user);

savedFunction();


Output

Sara


Comparison Table

Featurecall()apply()bind()
Sets thisYesYesYes
Executes immediatelyYesYesNo
ArgumentsSeparateArraySeparate initially

Real-World Use Cases

MethodCommon Usage
call()Method borrowing
apply()Dynamic argument arrays
bind()Event handlers/callbacks

Common Beginner Mistake

Incorrect:

const fn = greet.bind(user)();

This immediately executes.

Better:

const fn = greet.bind(user);

fn();


Easy Way to Remember

MethodMemory Trick
call()Call now
apply()Apply array
bind()Bind later

Assignment

1. Create Object With Method

const student = {
  name: "Ali",

  show() {
    console.log(this.name);
  }
};

student.show();


2. Borrow Method Using call()

const anotherStudent = {
  name: "Sara"
};

student.show.call(anotherStudent);


3. Use apply()

function multiply(a, b) {
  console.log(a * b);
}

multiply.apply(null, [4, 5]);


4. Use bind()

const boundShow = student.show.bind(anotherStudent);

boundShow();


Key Takeaways

ConceptSummary
thisDepends on caller
call()Executes with custom this
apply()Same as call but uses array
bind()Returns new bound function
Main DifferenceImmediate vs delayed execution

Final Notes

Understanding this, call(), apply(), and bind() is important because they are heavily used in:

  • React

  • Event handling

  • Object-oriented JavaScript

  • Callbacks

  • Framework internals

The most important idea:

`this` depends on how a function is called


0 Comments

Sign in to join the conversation

No comments yet. Be the first to comment!