var now = moment();
var fiveMinutesLater = now.add(5, 'minutes');
now === fiveMinutesLater // --> true
From the above, now
and fiveMinutesLater
are the same object reference and containing the same value.
Instead of modifying the original moment object, can I have add()
returning a new moment object with new value?
That is, after line 2, fiveMinutesLater
is really 5 minutes later than now
.
Clone it. Try this:
var fiveMinutesLater = moment(now).add(5, 'minutes');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.