DEV Community

Lautaro Suarez
Lautaro Suarez

Posted on

Accessing function in object or redux

Let`s see how will you be able to access to a function inside the same object.

In this post i will explain how to do it in objects which is more generally and we are going to go throw an specific case in redux.

Let`s start seeing how to do it in an object.

First we are going to see the case when the functions inside the object are not defining as an arrow function

Image description

As we can see on the first example we are using this in order to be able to call the other function inside the object.

Now let`s see another example of getting the data of an object but in this case when we are defining the function with arrow functions.

Image description

As we can see now with arrow functions we will have to call the object and then the function we want to use in order to able to access it.

Now let's see an example which is basically the same as before but in a real life case.

Let`s say we created a store with reducers and we want to access another reducer within the same object as the other reducer function.

In this specific case we will be defining the object function with arrow function.

Image description

As we can see is basically the same as after. Remember to always think in retrospective and always think about the foundations of javascript it does not matter how complex the code it is.

Hope someone found it helpful, thanks for reading.

Lautaro.

Top comments (0)