Medium'this' Binding🐛 Debug Challenge

bind is permanent — call cannot override it

Buggy Code — Can you spot the issue?

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

const alice = { name: 'Alice' };
const bob   = { name: 'Bob'   };

const boundAlice = getName.bind(alice);
boundAlice();
boundAlice.call(bob);

Fixed Code

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

const alice = { name: 'Alice' };
const bob   = { name: 'Bob'   };

const boundAlice = getName.bind(alice);
boundAlice();
getName.call(bob);

Bug Explained

Bug: bind permanently fixes this. .call(bob) cannot override a bound function — it still runs with alice as this.

Explanation: To use bob's context, call the original unbound function with .call(bob) — not the bound version.

Key Insight: bind() creates a permanently bound function. call/apply cannot override it. Keep a reference to the original if you need different contexts.

More 'this' Binding Debug Challenges

EasyMethod detached from object loses thisEasyArrow function as object method has no own thisMediumRegular callback inside method loses this

Practice spotting bugs live →

38 debug challenges with AI hints

🐛 Try Debug Lab