Modern way to create static or Class variable for Javascript class
<p>I've been hunting around for a clear answer to this, and most of what pops up still relates to the old (or should I say "traditional") way of defining classes using <code>function</code>.</p>

<p>According to <a href="https://stackoverflow.com/a/37480300/188963">this SO answer</a>,</p>

<blockquote>
  <p>Class properties are not supported in ES2015.</p>
</blockquote>

<p>As far as I can tell, the only way to add a static variable to a class is like:</p>

<p><a href="https://jsfiddle.net/abalter/fknwx3n4/" rel="nofollow noreferrer">https://jsfiddle.net/abalter/fknwx3n4/</a></p>

<pre><code>class C {

  constructor(x) {
    console.log("in constructor " + x);
    this.x = x;
    this.add(this.x);
  }

  add(x) {
    console.log("in add " + x);
    C.alist.push(x);
  }

  show() {
    console.log("in show");
    console.log(C.alist);
  }
}

// MUST be done outside of actual class definition.
C.alist = [];

c1 = new C(5);
c1.show();
c2 = new C(10);
c1.show();
c2.show();
</code></pre>

<p>Is this the end of the story? Just seems so strange to not be able to do it INSIDE the class definition.</p>