I'm about a day and a half researching about Maps and Proxies to delve deeper into the issue of looking at arrays, objects, and so on. But I came across a problem, I can not use Proxy in Map. When it comes to an ordinary array, I can use Proxy without problems, but I do not know how to do it correctly in the case of Maps.
let teste = new Map();
let teste_proxy = new Proxy(teste, {
get: function(target, property, receiver) {
// property is index in this case
return target[property]
},
set: function(target, property, value, receiver) {
target[property] = value;
// you have to return true to accept the changes
return true;
}
});
console.log(teste_proxy);
teste_proxy.set("foo", "bar");
If you ran the code, you saw that it returned an error. I think it's because it's using the "get" part to return the "set" function of "Map", but how would I correctly return the function by passing the appropriate values to it?