title: How do I use composition with es6 classes in the same way as this example does using factory functions?
body: <p>(please note this is not a duplicate question, see @Jeff M's answer below)</p>
  
  <p>I am trying to understand es6 class syntax. I want to compose my classes in the same way as this code does using factory functions:</p>
  
  <p>Example 1:</p>
  
  <pre><code>const barker = (state) =&gt; ({
    bark: () =&gt; console.log("Woof, I am " + state.name)
  });
  
  const driver = (state) =&gt; ({
    drive: () =&gt; state.position = state.position + state.speed
  });
  
  const murderRobotDog = (name) =&gt; {
    let state = {
      name,
      speed: 100,
      position: 0
    };
    return Object.assign({},
      barker(state),
      driver(state)
    );
  };
  
  const bruno = murderRobotDog("bruno");
  bruno.bark(); // "Woof, I am Bruno"
  </code></pre>
  
  <p>My working example of class composition using 'class' from a completely different tutorial looks like this:</p>
  
  <p>Example 2:</p>
  
  <pre><code>class Employee {
    constructor(firstName, familyName) {
    this._firstName = firstName;
    this._familyName = familyName;
    }
  
    getFullName() {
    return `${this._firstName} ${this._familyName}`;
    }
  }
  
  class Group {
    constructor(manager /* : Employee */ ) {
      this._manager = manager;
      this._managedEmployees = [];
    }
  
    addEmployee(employee) {
      this._managedEmployees.push(employee);
    }
  }
  </code></pre>
  
  <p>I can see how the concept of composition works, but these seem like very different ways of doing it. The first example using the factories seems the most intuitive, but I want to use the es6 class syntax (don't worry why :)</p>
  
  <p>Maybe I am missing something and the answer is obvious, but how would I do exactly what is done in example 1 using es6 classes in the most simplistic way? THANKS.</p>