Rizal writes a tally on whatever scoreboard this is: counter.inc(), call(other), hung as the kentungan’s click handler, called bare, or bound; the call site…
Why it matters
"this is undefined" is one of the most confusing JS errors for beginners. The key: this is not tied to where a function is written, but to the call site. Once you see that, callback and event handler bugs read themselves.
The key idea
this is decided by HOW it is called, not where it is written
Common mistakes
this.count is not a function or undefined when a method is passed as a callbackthis is lost because there is no dot at the call site. Wrap it in an arrow () => obj.method() or use obj.method.bind(obj).
An arrow function used as an object method reads the wrong this An arrow has no this of its own; it takes the this from outside the object. For a method, use a plain method() {}.
A class method loses this when passed as an event handler Class methods are not bound automatically: as a handler, its this is the clicked element. Wrap it in an arrow, bind it in the constructor, or write it as an arrow field: handler = () => { … }.
Try it in this playground
Call through the dot: counter.inc() counter is left of the dot, so this = counter, and counter’s board goes up.
Take it off its object: f() Without a dot, this is undefined in strict code: a TypeError. The most common callback bug.
Hang inc straight on the kentungan As an event handler, this = the element. No error, but kentungan.count becomes NaN and counter is untouched.
Fix it with an arrow or bind() => counter.inc() brings the dot back; bind(counter) locks this. Both write on counter.