Skip to content

Instantly share code, notes, and snippets.

View LuisMiguelFilipe's full-sized avatar

Luís Filipe LuisMiguelFilipe

View GitHub Profile
@LuisMiguelFilipe
LuisMiguelFilipe / JS-getter-with-proxy
Created November 6, 2021 08:28
Javascript calculated property which is serializable
// Typescript accessor fields are not part of the serilization process
// A Proxy object serves the purpose ina very elegant way
// Other alternative would be to use `Object.defineProperty`
class Q {
constructor(init: number) {
var proxy = new Proxy(this, {
get: (target, prop, receiver) => {
if (prop === "msg") {
return `Number is ${this.value}`;