title: dynamic object construction in javascript?
body: <p>When I want to call a function in javascript with arguments supplied from elsewhere I can use the <code>apply</code> method of the function like:</p>
  <pre><code>array = [&quot;arg1&quot;, 5, &quot;arg3&quot;] 
  ...
  someFunc.apply(null, array);
  </code></pre>
  <p>but what if I need to call a constructor in a similar fashion? This does not seem to work:</p>
  <pre><code>array = [&quot;arg1&quot;, 5, &quot;arg3&quot;] 
  ...
  someConstructor.apply({}, array);
  </code></pre>
  <p>at least not as I am attempting:</p>
  <pre><code>template = ['string1', string2, 'etc'];
  var resultTpl = Ext.XTemplate.apply({}, template);
  </code></pre>
  <p>this does not work wither:</p>
  <pre><code>Ext.XTemplate.prototype.constructor.apply({}, template);
  </code></pre>
  <p>Any way to make that one work? (In this particular case I found that <code>new Ext.XTemplate(template)</code> will work, but I am interested in the general case)</p>
  <p>similar question but specific to built-in types and without an answer I can use:
  <a href="https://stackoverflow.com/questions/181348/instantiating-a-javascript-object-by-calling-prototypeconstructorapply">Instantiating a JavaScript object by calling prototype.constructor.apply</a></p>
  <p>Thank you.</p>
  <h1>Edit:</h1>
  <p>Time has passed and ES6 and transpilers are now a thing.
  In ES6 it is trivial to do what I wanted: <code>new someConstructor(...array)</code>.
  <a href="http://babeljs.io" rel="noreferrer">Babel</a> will turn that into ES5 <code>new (Function.prototype.bind.apply(someConstructor, [null].concat(array)))();</code> which is explained in <a href="https://stackoverflow.com/questions/4226646/how-to-construct-javascript-object-using-apply/4226801#4226801">How to construct JavaScript object (using 'apply')?</a>.</p>