Skip to content
Advertisement

Tag: this

How to access an array from the scope of a function

I’m trying to add an element into an array with the push() method but apparently, I can’t access that array from the scope of my function. Here’s a summary of my architecture : I know for sure that the problem come from the array. When executing the code, I have an error telling me that push isn’t a propriety of

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 work in rather a similar

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

Javascript call() & apply() vs bind()?

I already know that apply and call are similar functions which set this (context of a function). The difference is with the way we send the arguments (manual vs array) Question: But when should I use the bind() method ? jsbin Answer I created this comparison between function objects, function calls, call/apply and bind a while ago: .bind allows you

Advertisement