Object.freeze in constructor with subclasses
<p>If I want my classes to be immutable, I understand I can use <code>Object.freeze()</code>. Now if I want my objects to be immutable after construction, I would put <code>Object.freeze(this)</code> into my constructor as the last line. But now, if I want to subclass that, I can't add more parameters because I can't call <code>this</code> before calling <code>super</code> and after calling <code>super</code> it's immutable:</p>

<pre><code>class A {
  constructor(x) {
    this.x = x
    Object.freeze(this)
  }
}

class B extends A {
  constructor(x, y) {
    this.y = y // nope. No "this" before "super"
    super(x)
    this.y = y // nope. "this" is already frozen
    Object.freeze(this)
  }
}
</code></pre>

<p>I was thinking about figuring out if the constructor was called via super in order to skip freezing and leaving freezing to the subclass but that would leave it to the subclass to freeze or not. How would I best approach this? With a factory maybe?</p>