title: Dynamically extending a class in javascript
body: <p>How can we dynamically/programmatically extend a javascript class?</p>
  
  <p>More concretely, given something like </p>
  
  <pre><code>class Polygon {
    constructor(area, sides) {
      this.area = area;
      this.sides = sides;
    }
  }
  
  const Rectangle = extend(Polygon, (length, width) =&gt; {
    super(length * width, 4);
    this.length = length;
    this.width = width;
  });
  </code></pre>
  
  <p>how can we implement something like <code>extend</code> such that it behaves the same as </p>
  
  <pre><code>class Rectangle extends Polygon {
    constructor(length, width) {
      super(length * width, 4);
      this.length = length;
      this.width = width;
    }
  }
  </code></pre>
  
  <p>?</p>