title: Use of .apply() with 'new' operator. Is this possible?
body: <p>In JavaScript, I want to create an object instance (via the <code>new</code> operator), but pass an arbitrary number of arguments to the constructor. Is this possible?</p>
  
  <p>What I want to do is something like this (but the code below does not work):</p>
  
  <pre><code>function Something(){
      // init stuff
  }
  function createSomething(){
      return new Something.apply(null, arguments);
  }
  var s = createSomething(a,b,c); // 's' is an instance of Something
  </code></pre>
  
  <hr>
  
  <p><strong>The Answer</strong></p>
  
  <p>From the responses here, it became clear that there's no built-in way to call <code>.apply()</code> with the <code>new</code> operator. However, people suggested a number of really interesting solutions to the problem.</p>
  
  <p>My preferred solution was <a href="https://stackoverflow.com/questions/1606797/use-of-apply-with-new-operator-is-this-possible/#1608546">this one from Matthew Crumley</a> (I've modified it to pass the <code>arguments</code> property):</p>
  
  <pre><code>var createSomething = (function() {
      function F(args) {
          return Something.apply(this, args);
      }
      F.prototype = Something.prototype;
  
      return function() {
          return new F(arguments);
      }
  })();
  </code></pre>