The best way to avoid this losing context is to not use this at all. However, this is not always an option. We may have inherited code that uses this or we might work with a library making use of this.

Object literals, constructor functions, and classes build objects over the prototype system. The this pseudo-parameter is used by the prototype system to give functions access to the other object properties.

this can lose context in different situations.

bind(), the that/self pattern, and arrow functions are tools at our disposal for solving the context problems.

Factory functions give the option of creating objects without using this at all.

Discover Functional JavaScript was named one of the best new Functional Programming ebooks by BookAuthority!

For more on applying functional techniques to React take a look at Functional React.

Learn how to apply the Principles of Design Patterns.

You can find me on Medium and Twitter.