Skip to content

Tag: this

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… …but it feels like an awkward solution for multiple nested functions. Does anyone know of a more elegant solution? Answer You can use arrow functions. They […]

JS call static method from class

I have a class with a static method: Is there an equivalent to this for static methods (i.e. refer to the current class without an instance)? So I don’t have to write the class name: “User”. Answer From MDN documentation Static method calls are made directly on the class and are not callable on instances of the class. Static methods