title: Initiate random class from Class Array in JavaScript
body: <p>I have an array of Classes:</p>
  <pre><code>possibleEnemies: [
    Slime,
    (i currently have only one)
  ],
  </code></pre>
  <p>and I want to randomly select one of them and store them in a variable like this (they are all derived from the <code>Enemy</code> class):</p>
  <pre><code>this.enemy = new this.possibleEnemies[Math.floor(Math.random()*this.possibleEnemies.length)]()
  </code></pre>
  <p>Sadly doing it like that ^ doesn't work and it throws the error that it isn't a constructor:</p>
  <pre><code>[Vue warn]: Error in mounted hook: &quot;TypeError: this.possibleEnemies[Math.floor(...)] is not a constructor&quot;
  </code></pre>
  <p>I have done a lot of searching online on how to do it and couldn't find anything. Could anyone please help me?</p>
  <p>Enemy.js</p>
  <pre><code>export default class Enemy {
      minGold;
      maxGold;
      minMaxHealth;
      maxMaxHealth;
  
      maxHealth;
      health;
  
      attackSpeed;
      damage;
  
      constructor(mig, mag, mimah, mamah, mah, h, ats, dam){
          this.minGold = mig;
          this.maxGold = mag;
          this.minMaxHealth = mimah;
          this.maxMaxHealth = mamah;
          this.maxHealth = mah;
          this.health = h;
          this.attackSpeed = ats;
          this.damage = dam;
      }
  }
  </code></pre>
  <p>all.js (all enemies in one script)</p>
  <pre><code>import {default as Enemy} from &quot;./Enemy.js&quot;;
  
  export default class Slime extends Enemy {
      constructor() {
          super(
              1,
              3,
              3,
              6,
              6,
              6,
              7,
              8
          );
      }
  }
  </code></pre>