A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-158.js
1classCounter{
2n=0;
3inc=()=>++this.n;
4}
5constc=newCounter();
6constf=c.inc;
7console.log(f(),f());
Scope
Answer & explanation
Console output
1 2
Why
An arrow function assigned to a class field captures this lexically when the instance is constructed, permanently binding it to that instance. So extracting c.inc into f does not lose this. f() still increments c.n, yielding 1 then 2. This is why arrow class fields are a popular way to make auto-bound methods for callbacks.