Tip 42 | Resolve Context Problems with Bind() |
In this tip, youâll learn how to solve this errors with bind().
In Tip 36, â Prevent Context Confusion with Arrow Functions â, you saw how functions create a new context and how a new context can give you results you arenât expecting. Changing context can create confusion, particularly when youâre using the this keyword in callbacks or array methods.
Sadly, the problem doesnât go away in classes. Earlier, you learned how you can use arrow functions to create another function without a new context. In this tip, youâll learn more techniques for preventing context problems. The techniques youâre about to learn work on object literals and classes, but theyâre much more common in class ...
Get Simplifying JavaScript now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.