Is there a consolidated way of writing several prototype functions for a single object?

Posted by Christopher Altman on Stack Overflow See other posts from Stack Overflow or by Christopher Altman
Published on 2011-02-08T15:15:49Z Indexed on 2011/02/08 15:25 UTC
Read the original article Hit count: 234

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about prototype