Hint
Regular nested functions lose the outer this. Fix: use arrow function or const self = this.
const obj = {
value: 42,
getValue() {
function inner() {
return this?.value;
}
return inner();
}
};
console.log(obj.getValue());undefined
Explanation: inner() is called as a plain function, not as a method. So this inside inner is undefined (strict) or global. It does NOT inherit obj's this.
Key Insight: Regular nested functions lose the outer this. Fix: use arrow function or const self = this.