Вы можете изменить возвращаемое значение в соответствии с вашими потребностями, сейчас он просто возвращает полный объект Sunday.
Date.prototype.endWeek=function(){
return new Date(this.getFullYear(), this.getMonth(),(7-this.getDay())+this.getDate());
}
//call like this
var myDate = new Date();
var Sunday = myDate.endWeek();
alert("Sunday falls on "+ Sunday.getDate());