T
T
tarroma92021-09-20 15:23:58
JavaScript
tarroma9, 2021-09-20 15:23:58

Do I need to create variables inside object methods?

Good afternoon.
Not so long ago I started learning OOP in js.
I am rewriting the code to this standard, for the convenience of interacting directly with objects. Before that, there were many functions, some of which used global variables that were higher (so that other functions could have access).

For example:

let table = document.getElemetsByClassName("tab")[0]

And then the functions interacted with it (although now I understand that it’s probably better to make it a constant.

I don’t quite understand whether to put it in the properties of the object or make a separate function and then assign the resulting object to the property and access it through this.

Of course, properties can be an object, but here with let, it's just to present such an entry.
Obj = {table : document.getElemetsByClassName("tab")[0]}

It seems strange. Or is this not normal? Or is it better to do something like this directly in the method and assign a value to the property?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question