js prototype属性,类似.net扩展方法

prototype 属性使您有能力向对象添加属性和方法。

类似.net扩展方法

定义:

String.prototype.toWeekName = function () {
    var newDate = new Date(this.replace(/-/g, '/'));
    var weekday = new Array(7);
    weekday[0] = "星期日";
    weekday[1] = "星期一";
    weekday[2] = "星期二";
    weekday[3] = "星期三";
    weekday[4] = "星期四";
    weekday[5] = "星期五";
    weekday[6] = "星期六";
    return weekday[newDate.getDay()];
}

调用

            var day = new Date();
            var month = (day.getMonth() + 1) < 10 ? ("0" + (day.getMonth() + 1)) : (day.getMonth() + 1);
            var date = day.getDate() < 10 ? ("0" + day.getDate()) : day.getDate();
            var dayformat = day.getFullYear() + "-" + month + "-" + date;
            var week = dayformat.toWeekName();//调用

 

posted @ 2016-01-07 15:11  直钩钓鱼  阅读(175)  评论(0编辑  收藏  举报