So if I write a class as follows
class Rectangle {
#width;
#height;
constructor() {
this.#width = 3;
this.#height = 5;
}
}
let rect = new Rectangle();
console.log(JSON.stringify(rect)); // returns {}
It will return an empty object, totally ignoring all of my private members. Adding a toJSON method works but that becomes very cumbersome. Is there any built-in way that I can easily get my private fields to show up in JSON.stringify? Or do I just have to write in every single member into a toJSON method?