prototype 属性使您有能力向对象添加属性和方法。
类似.net扩展方法
定义:
String.prototype.toWeekName = function () {
var newDate = new Date(this.replace(/-/g, '/'));
var weekday = new Array();
weekday[] = "星期日";
weekday[] = "星期一";
weekday[] = "星期二";
weekday[] = "星期三";
weekday[] = "星期四";
weekday[] = "星期五";
weekday[] = "星期六";
return weekday[newDate.getDay()];
}
调用
var day = new Date();
var month = (day.getMonth() + ) < ? ("" + (day.getMonth() + )) : (day.getMonth() + );
var date = day.getDate() < ? ("" + day.getDate()) : day.getDate();
var dayformat = day.getFullYear() + "-" + month + "-" + date;
var week = dayformat.toWeekName();//调用