JS 联接函数(链式函数)


Date.prototype.addDay = function (value) {
this.setDate(this.getDate() + value);
return this;
}
Date.prototype.addMonth = function (value) {
this.setMonth(this.getMonth() + value);
return this;
}
Date.prototype.addYear = function (value) {
this.setFullYear(this.getFullYear() + value);
return this;
}
Date.prototype.formatToYMD=function(date) {
return this.getFullYear() + '-' + (this.getMonth() + 1) + '-' + this.getDate();
}

var ndt = new Date("2015-12-31");
ndt = ndt.addDay(1);
ndt = ndt.addMonth(1);
ndt = ndt.addYear(1);
var ndt2 = new Date("2015-12-31");
ndt2 = ndt2.addYear(1).addDay(1).addMonth(1).formatToYMD();


console.log("明年下个月的明天 " + ndt);
console.log("明年下个月的明天 " + ndt2);

posted @ 2015-09-10 08:05  大漠孤烟~  阅读(627)  评论(0编辑  收藏  举报