To use 'this' or to not use 'this'?

What's the convention surrounding using 'this' in functions? Is it good practice? I've never seen it used before this book and personally just declare my variables using 'const'.


Link to content: JavaScript: Best Practice - Section 1

To be honest using this without a class is very special to javascript and confuses me a little bit every time I see it.
Thats the reason why I do not use this on functions but only on classes. But that’s a personal preference.

2 Likes

this also has context.

I personally wouldnt use it in pseudo-classes like that, but I do use it in, for example, event binders where i’m going to bind an effect to multiple items; for example, a set of buttons that will disable itself on click, then check to see if a certain number of the buttons have been disabled.

2 Likes

I think you might find the following useful: