I've reviewed previous posts on this problem, but have not been able to get the generally proposed solution to work for me. evtList is a global array of objects of type "Event". Previous posts have indicated that creating a local object ("newEvent") inside my loop, defining it's elements, and then pushing the local object into the global array should work. However, I've found that as soon as I declare a new value for an element in the newEvent object, all the objects in the global array are changed to that set of values even before the push operation. What have I missed?
var i = 0;
var nextTime = new Date();
while (evtList[i].evtTime < dayEnd) {
i++;
var newEvent = new Event;
var milliSecs = (evtList[i-1].evtTime).getTime() + gaussian(arrStations[0].mean, arrStations[0].stdDev);
nextTime.setTime(milliSecs);
newEvent = ({value: 1, station: 0, evtTime: nextTime});
evtList.push(newEvent);
}
evtTimewill be the same for all objects because they all reference the same date (nextTime). Beside that, thenewEventelement you push is a plain JavaScript object and not an object of the typeEvent.