Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Arrow functions don't work sometimes as event handlers
I find that when I write the event handler as an arrow function, whenever I'm using $(this) it doesn't work, but when I write a regular function the $(this) works.
Steven Parker218,583 Points
You've discovered one of the main differences between conventional and arrow functions: the binding of "this" was intentionally omitted. There are a few others, for full details see this MDN page on Arrow Functions.
Arrow functions are not intended as a universal replacement for conventional functions. In particular, the documentation says:
Arrow function expressions are ill suited as methods, and they cannot be used as constructors.
Oh I see. Arrow functions are not scoped as regular functions.