E
E
eternal_blue2020-07-01 17:03:28
JavaScript
eternal_blue, 2020-07-01 17:03:28

How to define a common variable for all objects?

Hello, I want to make such a system on the site that there are two side menus with additional menus on the main desktop. actions. You press a button, a menu with additional settings appears on the left, you press another, a menu appears on the right, you press a third, the former left menu closes and a new one appears in its place. I implement it through the Sidemenu class, and in order for the system to determine which sides are occupied and which are not, I entered an array outside the class = [0,0] (for the left and right sides, 0 there is no menu, 1 there is a menu). But for certain reasons, it will be more convenient for me to have such an array inside the class, one for all, i.e. changing it in one object will cause it to change in all objects, as well as for newly created objects. Is there such a possibility in js?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Klimenko, 2020-07-01
@eternal_blue

Look at static variables in classes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question