Answer the question
In order to leave comments, you need to log in
What is this bug in JS?
Bug! I CAN'T say otherwise. I'm just making an array of objects. Each next push() replaces all previous objects with the latest one! Look: pastebin.com/xwU2UV3t
The last print is outside the cycle, as you can see there is no difference
Answer the question
In order to leave comments, you need to log in
In tokens you put an object. and not a copy of the object at all at the time of donation to tokens. In fact, a reference to an object. So it is logical that when an object changes in one place, from all other places it looks like it has changed.
In tokens, you need to put not an object, but a copy of it. For example, so .
Judging by the output (because you provided a minimum of code), all array elements this.tokens
are references to the same variable, which changes in each iteration of the loop. Without more code, it's hard to say anything concrete.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question