码迷,mamicode.com
首页 > Web开发 > 详细

JS 联接函数(链式函数)

时间:2015-09-10 08:25:09      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:


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);

JS 联接函数(链式函数)

标签:

原文地址:http://www.cnblogs.com/denghuachengle/p/4796712.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!