Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialClement Yam
15,984 PointsWhy can't we use "this" in an event handler of an object method?
Hello,
https://teamtreehouse.com/library/objectoriented-javascript/practice-project/user-interface-code
In Andrew's code quiz_UI file, I understood that the "this" keyword corresponds to the Object QuizUI. Then why can't we use this.displayNext() in the guessHandler method?
Thank you in advance for your answers!
Clement Yam
15,984 PointsOops! My bad I updated my question with the link to the video.
1 Answer
Steven Parker
229,644 PointsCan you provide the code and/or a link to the video?
But my first thought is that this may cause some confusion since normally in a handler, "this" refers to the element that triggered the event (the "event target"), but inside an object, "this" would normally be a reference to the object instance.
Clement Yam
15,984 PointsI see it more clearly now, thank you for your quick response!
Clayton Perszyk
Treehouse Moderator 48,723 PointsClayton Perszyk
Treehouse Moderator 48,723 Pointscould post a link to the video/lesson this question refers to. Thanks!