const monster1 = { eyeCount: 4 };
const handler1 = {
set(obj, prop, value) {
if (prop === 'eyeCount' && value % 2 !== 0) {
console.log('Monsters must have an even number of eyes');
} else {
return Reflect.set(...arguments);
}
},
};
const proxy1 = new Proxy(monster1, handler1);
proxy1.eyeCount = 1;
// Expected output: "Monsters must have an even number of eyes"
console.log(proxy1.eyeCount);
// Expected output: 4
proxy1.eyeCount = 2;
console.log(proxy1.eyeCount);
// Expected output: 2