title: Instantiating a JavaScript object by calling prototype.constructor.apply
body: <p>Let me start with a specific example of what I'm trying to do.</p>
  
  <p>I have an array of year, month, day, hour, minute, second and millisecond components in the form <code>[ 2008, 10, 8, 00, 16, 34, 254 ]</code>. I'd like to instantiate a Date object using the following standard constructor:</p>
  
  <pre><code>new Date(year, month, date [, hour, minute, second, millisecond ])
  </code></pre>
  
  <p>How can I pass my array to this constructor to get a new Date instance? <em>[ <strong>Update</strong>: My question actually extends beyond this specific example. I'd like a general solution for built-in JavaScript classes like Date, Array, RegExp, etc. whose constructors are beyond my reach. ]</em></p>
  
  <p>I'm trying to do something like the following:</p>
  
  <pre><code>var comps = [ 2008, 10, 8, 00, 16, 34, 254 ];
  var d = Date.prototype.constructor.apply(this, comps);
  </code></pre>
  
  <p>I probably need a "<code>new</code>" in there somewhere. The above just returns the current time as if I had called "<code>(new Date()).toString()</code>". I also acknowledge that I may be completely in the wrong direction with the above :)</p>
  
  <p><strong><em>Note</strong>: No <code>eval()</code> and no accessing the array items one by one, please. I'm pretty sure I should be able to use the array as is.</em></p>
  
  <hr>
  
  <h2>Update: Further Experiments</h2>
  
  <p>Since no one has been able to come up with a working answer yet, I've done more playing around. Here's a new discovery.</p>
  
  <p>I can do this with my own class:</p>
  
  <pre><code>function Foo(a, b) {
      this.a = a;
      this.b = b;
  
      this.toString = function () {
          return this.a + this.b;
      };
  }
  
  var foo = new Foo(1, 2);
  Foo.prototype.constructor.apply(foo, [4, 8]);
  document.write(foo); // Returns 12 -- yay!
  </code></pre>
  
  <p>But it doesn't work with the intrinsic Date class:</p>
  
  <pre><code>var d = new Date();
  Date.prototype.constructor.call(d, 1000);
  document.write(d); // Still returns current time :(
  </code></pre>
  
  <p>Neither does it work with Number:</p>
  
  <pre><code>var n = new Number(42);
  Number.prototype.constructor.call(n, 666);
  document.write(n); // Returns 42
  </code></pre>
  
  <p>Maybe this just isn't possible with intrinsic objects? I'm testing with Firefox BTW.</p>