1
I’m about a day and a half researching about Maps and Proxies to go deeper into the issue of looking at arrays, objects and so on. But I came across a problem, I can’t use the Proxy in the Map. When it comes to a common array, I can use the Proxy without problems, but I don’t 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 executed the code, you saw that it returns an error. I believe it is because he is using the "get" part to return the "set" function of the "Map", but how to correctly return the function passing the appropriate values to it ?
Thank you so much! You helped me so much.
– Joao Scheuermann
@Joaoscheuermann great! It took me a while to realize what was missing there :) Good year!
– Sergio
For you too, I spent hours and hours trying to solve this, but I didn’t think it was about the context :P
– Joao Scheuermann