Is there a consolidated way of writing several prototype functions for a single object?
- by Christopher Altman
I have about eight prototype functions for the Date object. I would like to avoid repeating Date.prototype. Is there a consolidated way of writing several prototype functions for a single object?
I tried this to no avail:
Date.prototype = {
getMonthText: function(date){
var month = this.getMonth();
if(month==12) month = 0;
return ['JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC'][month];
},
getDaysInMonth: function(date){
return 32 - new Date(this.getFullYear(), this.getMonth(), 32).getDate();
}
};