Hint
Proxy get trap intercepts ALL property access including inherited ones. "prop in target" checks own + prototype chain. Use hasOwnProperty for own-only check.
const handler = {
get(target, prop) {
return prop in target ? target[prop] : `'${prop}' not found`;
}
};
const obj = new Proxy({ name: 'Alice', age: 25 }, handler);
console.log(obj.name);
console.log(obj.age);
console.log(obj.email);
console.log(obj.toString === Object.prototype.toString);Alice 25 'email' not found false
Explanation: name and age exist β return normally. email doesn't exist β trap returns message string. toString: "toString" is not "in" the plain obj (it's inherited) β so trap returns a string, not the function. obj.toString !== Object.prototype.toString.
Key Insight: Proxy get trap intercepts ALL property access including inherited ones. "prop in target" checks own + prototype chain. Use hasOwnProperty for own-only check.