title: How to add mixins to ES6 javascript classes?
body: <p>In an ES6 class with some instance variables and methods, how can you add a mixin to it? I've given an example below, though I don't know if the syntax for the mixin object is correct.</p>
  
  <pre><code>class Test {
    constructor() {
      this.var1 = 'var1'
    }
    method1() {
      console.log(this.var1)
    }
    test() {
      this.method2()
    }
  }
  
  var mixin = {
    var2: 'var2',
    method2: {
      console.log(this.var2)
    }
  }
  </code></pre>
  
  <p>If I run <code>(new Test()).test()</code>, it will fail because there's no <code>method2</code> on the class, as it's in the mixin, that's why I need to add the mixin variables and methods to the class.</p>
  
  <p>I see there's a lodash mixin function <a href="https://lodash.com/docs/4.17.4#mixin" rel="noreferrer">https://lodash.com/docs/4.17.4#mixin</a>, but I don't know how I could use it with ES6 classes. I'm fine with using lodash for the solution, or even plain JS with no libraries to provide the mixin functionality.</p>