I don't seem to understand why all the foo.dates are the same value. I was expecting it to increase by one day for each iteration.
If anyone could explain why and a possible solution that would be nice :)
Thank you.
Date.prototype.nextDay=function()
{
this.setDate(this.getDate()+1);
return this;
}
aDate = new Date(0);
function foo()
{
this.date = aDate.nextDay();
}
ary = new Array();
for (i=1;i<5;i++){
ary.push(new foo());
}
console.log(JSON.stringify(ary, null, 4));
Foo Objects:
[
{
"date": "1970-01-05T00:00:00.000Z"
},
{
"date": "1970-01-05T00:00:00.000Z"
},
{
"date": "1970-01-05T00:00:00.000Z"
},
{
"date": "1970-01-05T00:00:00.000Z"
}
]