Skip to content
Advertisement

ES6 Classes: Bind “this” to nested functions

I have multiple nested functions in a ES6 Class. Now I wonder how I can easily bind this of the class instance to all the subfunctions.

I know of…

JavaScript

…but it feels like an awkward solution for multiple nested functions.

Does anyone know of a more elegant solution?

JavaScript

Advertisement

Answer

You can use arrow functions. They work in rather a similar manner. The arrow notation will replace this with the value of the context of the arrow function’s scope.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement