'Set Trap execute for two times - JS Proxy
Im working with proxies in js, but something is weird =>
let _usernames = [];
_usernames = new Proxy(_usernames, {
set(target, prop, val) {
console.count(); //this execute for two times!
if(typeof val === 'string') {
target[prop] = val;
return true;
} else {
return false;
}
}
});
_usernames.push('Manuel');
The Set trap should call only once when i push to the array, but it executed twice.
And there is an error in the console, when i push to array =>
Uncaught TypeError: proxy set handler returned false for property '"length"'
How can i fix this and what's wrong?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
