There is a code

var znak = parseFloat($('td').eq(2).html()) || 0, lng0 = znak; var znac = setInterval(function (){ znak = lng0 = parseFloat($('td').eq(2).html()); },2000); var znak1 = parseFloat($('td').eq(3).html()) || 0, lat1 = znak1; var znac = setInterval(function (){ znak1 = lat1 = parseFloat($('td').eq(3).html()); },2000); 

With the help of which I get data, and if the data has not yet been received, then I set the initial value to 0 .

The code helped me a lot in the project, but I will have about 50-100 such markers, and finding each of them values ​​is not an option ...

How can I improve this code ???

  • 2
    In the last question I already wrote how to change these intervals, and replace them at all with one interval - Grundy
  • Remove the jelly and use vanilla - Arthur
  • can you give a link? - elik
  • can you link to your vanilla?) - elik
  • one
    vanilla is not in terms of the framework, but pure js - Arthur

1 answer 1

Well, in order:

First, replace this translit with something less traumatic vision and psyche.

Then, combine all actions under the intervals into ONE interval in which all these "markers" will be run around, as was repeatedly suggested earlier.

After that, it would be nice to take out the multiple- use functional in, respectively, the function. I do not really understand the essence of everything that is happening, but if it is so desired, everything that is done before the interval in one function, everything that comes after is in the other.

Well, and again, as indicated earlier, using VanillaJS is a tool, though difficult to master, but as soon as you know it, the unimaginable power of this programming giant will open up.