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.