在遗留项目中找到此代码
var d = new Date();
d.setFullYear(currentYear);
d.setMonth(currentMonth);
d.setDate(currentDay);
尝试通过执行 d.setFullYear(currentYear).setMonth(currentMonth).setDate(currentDay)
来链接它,但出现错误。有更好的方法来重构上面的代码吗?
最佳答案
链接不是出于自身目的,无需重构此代码。
但是,如果您想缩短它,您可以使用 all three parameters of setFullYear
:
var d = new Date();
d.setFullYear(currentYear, currentMonth, currentDay);
关于javascript - javascript 中的日期无法链接方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42848515/