Date.prototype : prototype « Date « JavaScript Tutorial






Syntax

Date.prototype.property

    Date.prototype.method

The prototype property allows you to add new properties and methods to the Date object that can be used throughout your code.

<html>
    <script>
    <!--
    function getDayString()
    {
      var day
      switch(this.getDay())
      {
        case 0:
          day="Sunday";
          break;
        case 1:
          day="Monday";
          break;
        case 2:
          day="Tuesday";
          break;
        case 3:
          day="Wednesday";
          break;
        case 4:
          day="Thursday";
          break;
        case 5:
          day="Friday";
         break;
        case 6:
          day="Saturday";
          break;
        default:
          day="Invalid day";
      }
      return(day);
    }

    //Make the getDayString function available to all Date objects

    Date.prototype.getDayString = getDayString;
    var currentDate = new Date();

    document.write("<h2>Today is ",currentDate.getDayString(),"</h2>");
    -->

    </script>
    </html>








12.25.prototype
12.25.1.Date.prototype