title: Referencing static members from instance method on dynamically extended JS class
body: <p>I have a base ES6 class that I dynamically extend given a configuration object, like so:</p>
  
  <pre><code>class Model {
    constructor () {
      // ...
    }
  
    save () {
      // ...
    }
  }
  
  function createModelFromConfig (config) {
    const Impl = class extends Model {};
    Object.assign(Impl, config);
    return Impl;
  }
  
  const User = createModelFromConfig({store: new DbStore()});
  </code></pre>
  
  <p>In the <code>save()</code> method on the abstract Model, I'd like to reference the static object <code>store</code>, which will exist on the class that extends Model. This means, of course, that I need to reference a static member but the extended class is anonymous.</p>
  
  <p>Just in a quick test using the Chrome console, I tried</p>
  
  <pre><code>function X () {}
  X.prototype.doSomething = function () { console.log(this.constructor); };
  function Y () {}
  Y.prototype = Object.create(X.prototype);
  new Y().doSomething(); // function X () {}
  </code></pre>
  
  <p>I don't know if this is a reliable test, but it appears that <code>this.constructor</code> does not reference the Impl that I extended, but instead the original base class, which isn't helpful.</p>
  
  <p>A less elegant way is to add <code>Impl.prototype.Impl = Impl;</code> so I can use <code>this.Impl.store</code> in my save function, but it'd be preferable if I could access the static members of the Impl class without this.</p>
  
  <p>Is my prototypal test in the console inadequate? Or is there any other way to access the constructor class in an instance method from an inherited method?</p>