Skip to content
Preptima
mediumConceptCodingEntryMidSenior

How is `this` determined in JavaScript, and why does a method lose it when you pass it as a callback?

JavaScript `this` binding is decided by the call site: method calls bind the receiver, constructors bind the new object, bind/call/apply bind explicitly, and callbacks often lose the receiver because the method was passed as a plain function. It also connects arrow functions to the point an interviewer is testing.

4 min readUpdated 2026-08-15

Answer

Short answer

In JavaScript, this is set by how a function is called, not where it is defined. Passing obj.method as a callback extracts the function from obj, so the receiver is lost and this becomes undefined in strict mode. Use bind, an arrow wrapper, or call the method through the object.

Was this answer helpful?

Likely follow-ups

  • What does `this` refer to inside an arrow function written at the top level of an ES module?
  • Why does `new` on a bound function ignore the bound receiver?
  • How would you write a decorator or wrapper that forwards `this` correctly to the function it wraps?
  • Why can an arrow function not be used as a constructor or a generator?

Related questions

Further reading

Related Topics