In my class there is an indexer this [key] = value as well as in the dictionary. How to make a getter and setter on an indexer, so that, for example, key, before getting a value by key, translate into json?
1 answer
Use Proxy :
let _data = { key: {value: 42} }, data = new Proxy(_data, { get(target, key){ if(key in target) return JSON.stringify(target[key]); else return null; } }); console.info(data.key); // {"value":42} |