title: Create an instance of a class in ES6 with a dynamic name?
body: <p>I want to be able to instantiate a particular ES6 class by passing a string variable to a function. Depending on the value of the variable, a different class will be created.</p>
  
  <p><em>Example</em> - I have 2 classes, <code>ClassOne</code>, <code>ClassTwo</code>. I want to be able to pass a variable to a function and get a new class back. The name of the class will be related to the variable - eg. passing <code>'Two'</code> will create <code>ClassTwo</code>.</p>
  
  <p>I <strong>don't</strong> want to just use a <code>switch</code> clause like this:</p>
  
  <pre><code>function createRelevantClass( desiredSubclassName )
  {
    let args = [],
        newClass;
  
    switch( desiredSubclassName )
    {
      case 'One' :
        newClass = new ClassOne(args);
        break;
      case 'Two' :
        newClass = new ClassTwo(args);
        break;
    }
  
    return newClass;
  }
  </code></pre>
  
  <p>Instead, I want to somehow be able to create the constructor call using the variable name. Is that possible?</p>
  
  <pre><code>function createRelevantClass( desiredSubclassName )
  {
    // desiredSubclassName would be string 'One' or 'Two'
  
    // how to use the 'new' operator or Reflect here to create the class based on the variable passed in
    let newClass = ( *magic code to build constructor dynamically* );
  
    return newClass;
  }
  </code></pre>