JavaScript·Intermediate·Coding·1 min read
How does this behave in arrow functions?
Short interview answer
An arrow captures this from its lexical environment and ignores call, apply, and bind attempts to replace it. That makes arrows useful for callbacks needing the enclosing instance, but unsuitable as dynamically bound object methods or constructors.
Example
const timer = { seconds: 0, start() { setInterval(() => { this.seconds++; }, 1000); // arrow: `this` is `timer` },};// A regular function here would get its own `this` (undefined/global).Key takeaway
Explain the underlying mental model clearly, then support it with a concrete example and its trade-offs.