function addMonth(date, offset) { if (date instanceof Date && !isNaN(offset)) { let givenMonth = date.getMonth(); let newMonth = givenMonth + offset; date.setMonth(newMonth); return date; } throw Error(‘argument type error‘); }
原文:https://www.cnblogs.com/wjs0509/p/11265487.html