Skip to content

Instantly share code, notes, and snippets.

@YonatanKra
Last active September 21, 2021 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YonatanKra/f50977caf38591efb7d79947415deece to your computer and use it in GitHub Desktop.
Save YonatanKra/f50977caf38591efb7d79947415deece to your computer and use it in GitHub Desktop.
class MyClass {
#somethingCool = 5;
get somethingCool() {
return this.#somethingCool;
}
set somethingCool(value) {
this.#somethingCool = value;
}
toJSON() {
return {
somethingCool: this.somethingCool,
}
}
}
const x = new MyClass();
JSON.stringify(x); // '{"somethingCool": 5}'
x.somethingCool = 10;
JSON.stringify(x); // '{"somethingCool": 10}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment