I'm using the date.js library.
Previous code:
alert(incidentDate);
var deadlineDate = incidentDate;
deadlineDate.add(2).years();
alert(incidentDate);
return;
Adding to the deadlineDate caused the incidentDate to change too. A bit of reading revealed that this was because objects in javascript are always assigned by reference. I've found a workaround (below), but it's blooming messy. There must be some neater way to do this, surely?
And besides, the workaround I've used applies only to Date objects. How would I deal with another object type?
Current code:
var deadlineDate;
deadlineDate = incidentDate.toString('yyyy-MM-dd');
alert(incidentDate);
alert(deadlineDate);
deadlineDate = Date.parse(deadlineDate);
alert(incidentDate);
alert(deadlineDate);
deadlineDate.add(2).years();
alert(incidentDate);
alert(deadlineDate);
return;
Note: All the alerts are just for debugging.