title: Overriding the Javascript Date constructor?
body: <p>I am developing a browser application that is sensitive to the current date.</p>
  
  <p>Throughout my application's code, I call <code>new Date</code> and perform calculations based on the current time and render the view accordingly.</p>
  
  <p>In order to test my application for different potential calendar days, I would have to constantly change my system clock to the past or future, which is an annoyance and probably not healthy for my computer.</p>
  
  <p>So purely for testing purposes (I would never use this code in production), I decided to override the built-in <code>Date</code> constructor by doing this in the console:</p>
  
  <pre><code>// create a date object for this Friday:
  var d = new Date(2012, 0, 20)
  //override Date constructor so all newly constructed dates return this Friday
  Date = function(){return d}
  </code></pre>
  
  <p>With this assumption in mind, I tried this and got strange results:</p>
  
  <pre><code>var now = new Date
  Sat Apr 07 2012 00:00:00 GMT-0400 (EDT)
  
  now = new Date
  Tue Jul 10 2012 00:00:00 GMT-0400 (EDT)
  
  now = new Date
  Wed Jul 09 2014 00:00:00 GMT-0400 (EDT)
  
  now = new Date
  Wed Jun 07 2023 00:00:00 GMT-0400 (EDT)
  </code></pre>
  
  <p>...and so on....</p>
  
  <p>My question is, what exactly is going on here?</p>
  
  <p>If I overrode the constructor to return a static date, why does it give unrelated and constantly incrementing dates?</p>
  
  <p>Also, is there an effective way I can override the Date constructor to return a static date in the future without having to go through all date instantiation calls in my code and modifying the output?</p>
  
  <p>Thanks in advance.</p>
  
  <p>EDIT:</p>
  
  <p>I tried my code in a fresh window and it worked as expected.</p>
  
  <p>It seems the culprit was the jQuery UI datepicker plugin which was calling its "refresh" method. When I disable its call, the date overriding works normally, but as soon as I use the datepicker, the strange behavior above occurs.</p>
  
  <p>No idea why this popular plugin would somehow affect something global like this. If anyone has any ideas, let me know.</p>
  
  <p>Sorry for not figuring out the true culprit earlier.</p>