A.6. The fat arrow

The fat arrow is a newer JS feature that solves a long-standing problem in the language. JS’s bind method, in addition to apply, solved this prior to ES2015. The fat arrow, or the arrow function, now solves the scope problem in a more readable way. This problem isn’t unique to Web Components, or classes, for that matter. The fat arrow allows us to preserve scope anywhere we need to. For Web Component classes specifically, it makes our event listeners and callbacks much more readable and easier to use.

A.6.1. The callback scope problem

You’re probably familiar with event listeners, as we use them all the time when checking for mouse events, keyboard input, as well as lots of other things. Typically, you’ll use them with two ...

Get Web Components in Action 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.