New: Cookbooks and AI ExplanationsStep-by-Step recipes to solve problems connected to Roadmaps and Cheat Sheets. Need more details? Use AI buttons for structured and simple explanations with concrete examples throughout the whole platform.Take a look
A method that reads this.count works fine on its own, but as soon as I pass it to addEventListener, this turns into the button.
What you'll have at the end
A class method that keeps reading the right this value no matter how it gets called as a handler
You need
A JavaScript class with a method that reads its own instance's properties through this, and a page that already hands that exact method straight to addEventListener as the click handler.
Not covered
Telling apart which element inside a group of near-identical ones actually fired the click; that calls for a different kind of listener entirely.
Fix a classic var-in-a-loop closure bug
when a handler logs the wrong loop index instead of losing this, that is a different scoping bug with the same event-handler shape
Make new list items respond to clicks with event delegation
when the real gap is that a listener never reaches an element added after the page loaded, event delegation covers that instead
Checked 21 Aug 2026
Part of the JavaScript cookbook