title: How to create an object inside class static method
body: <p>I'm starting to learn more about static methods in classes, and was wondering if the following is doable:</p>
  
  <ul>
  <li>Have a class that instantiate monsters (<code>class Monster {...}</code>)</li>
  <li>Allow someone to create a <code>monster</code> instance by passing all the properties they want the monster to have</li>
  <li>Have a static method (<code>Monster.create()</code>) that would generate a new <code>monster</code> instance and randomly assign properties, rather than require the values as inputs.</li>
  </ul>
  
  <p>My questions:
  1. Is this a terrible approach to doing this? And if not, 
  2. How do you create a new instance inside the static method?</p>
  
  <p>My first thought is that you can just have the static method return an object and do whatever logic you want to randomize the values of that object, but I wasn't sure if there was a better way. (I think that object would be outside the prototype chain of instances created with <code>new Monster(...)</code>?)</p>
  
  <p>Here's what I came up with for my first attempt, but this imperatively creates the Monster, mimicking the Monster class:</p>
  
  <pre><code>class Monster {
      constructor(hp) {
          this.hp = hp;
      }
  
      static create() {
          const obj = Object.create(Monster.prototype);
          obj.hp = Math.floor(Math.random() * 100);
          return obj;
      }
  
      attack(obj) {
          const randDamage = Math.floor(Math.random() * 10);
          console.log(`Monster deals ${randDamage} damage!`);
          obj.hp -= randDamage;
      }
  }
  
  
  const monster = Monster.create();
  const me = {hp: 100};
  monster.attack(me);
  console.log(me);  // { hp: 91 }
  </code></pre>
  
  <p>Is there a way to implement <code>create()</code> that uses the <code>Monster</code> class? Or is this the right way to do this?</p>