您的位置:首页 > Web前端 > JavaScript

JS 联接函数(链式函数)

2015-09-10 08:05 489 查看
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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: