Skip to content
JavaScript·Intermediate·Coding·1 min read

Why does const f = object.method; f() lose the object?

Short interview answer

The reference is extracted and then called as a plain function, so the member-call base object is no longer part of the call expression. Bind the method, wrap it in another function, or design the API so it does not depend on dynamic this.

Example

JavaScript
const user = { name: 'Ada', greet() { return `Hi ${this.name}`; } };
const g = user.greet;g();                       // "Hi undefined" — call site has no base objectconst bound = user.greet.bind(user);bound();                   // "Hi Ada"

Key takeaway

Explain the underlying mental model clearly, then support it with a concrete example and its trade-offs.

← Back to The this keyword

Related questions