title: How to extend the Javascript Date object?
body: <p>I'm trying to subclass/extend the native Date object, without modifying the native object itself.</p>
  
  <p>I've tried this:</p>
  
  <pre><code>    var util = require('util');
  
      function MyDate() {
          Date.call(this);
      }
      util.inherits(MyDate, Date);
  
      MyDate.prototype.doSomething = function() {
          console.log('Doing something...');
      };        
  
      var date = new MyDate();
      date.doSomething();
  
      console.log(date);
      console.log(date.getHours());
  </code></pre>
  
  <p>and this:</p>
  
  <pre><code>function MyDate() {
  
      }
  
      MyDate.prototype = new Date();
  
      MyDate.prototype.doSomething = function() {
          console.log("DO");
      }
  
      var date = new MyDate();
      date.doSomething();
      console.log(date);
  </code></pre>
  
  <p>In both cases, the <code>date.doSomething()</code> works, but when I call any of the native methods such as <code>date.getHours()</code> or even <code>console.log(date)</code>, I get 'TypeError: this is not a Date object.'</p>
  
  <p>Any ideas?  Or am I stuck to extending the top-level Date object?</p>