Serializing an ES6 class object as JSON
<pre><code>class MyClass {
  constructor() {
    this.foo = 3
  }
}

var myClass = new MyClass()
</code></pre>

<p>I'd like to serialize <code>myClass</code> object to json.   </p>

<p>One easy way I can think of is, since every member is actually javascript object (array, etc..) I guess I can maintain a variable to hold the member variables.</p>

<p><code>this.prop.foo = this.foo</code> and so on.  </p>

<p>I expected to find a <code>toJSON/fromJSON</code> library for class objects since I used them with other languages such as swift/java, but couldn't find one for javascript.  </p>

<p>Maybe class construct is too new, or what I'm asking can be somehow easily achieved without a library. </p>