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
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.
For more on applying functional programming techniques in React take a look at Functional React.
Read more on Vue and Vuex in A Quick Introduction to Vue.js Components.
Learn how to apply the Principles of Design Patterns.