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 trial

JavaScript

Clement Yam
Clement Yam
15,984 Points

Why 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!

Clayton Perszyk
Clayton Perszyk
Treehouse Moderator 48,723 Points

could post a link to the video/lesson this question refers to. Thanks!

Clement Yam
Clement Yam
15,984 Points

Oops! My bad I updated my question with the link to the video.

1 Answer

Steven Parker
Steven Parker
229,644 Points

Can 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
Clement Yam
15,984 Points

I see it more clearly now, thank you for your quick response!