对象属性设置为引用而不是值-如何更改此设置?

时间:2019-07-10 03:03:25

标签: javascript

如何将data.lastpmt分配为data.pmtdate的值?下面使用参考,我想要该值。

const data = {};
data.pmtdate = new Date();
console.log(data.pmtdate);
data.lastpmt = data.pmtdate;
console.log(data.lastpmt);
data.pmtdate.setMonth(data.pmtdate.getMonth() + 1);
console.log(data.lastpmt);



Result:
Tue Jul 09 2019 20:01:13 GMT-0700 (Pacific Daylight Time)
Tue Jul 09 2019 20:01:13 GMT-0700 (Pacific Daylight Time)
Fri Aug 09 2019 20:01:13 GMT-0700 (Pacific Daylight Time)

0 个答案:

没有答案