en.javascript.info/1-js/99-js-misc/01-proxy/01-error-nonexisting/task.md
peachesontour de2542378f
Typos
2020-06-29 21:26:07 -03:00

32 lines
667 B
Markdown

# Error on reading non-existent property
Usually, an attempt to read a non-existent property returns `undefined`.
Create a proxy that throws an error for an attempt to read of a non-existent property instead.
That can help to detect programming mistakes early.
Write a function `wrap(target)` that takes an object `target` and return a proxy that adds this functionality aspect.
That's how it should work:
```js
let user = {
name: "John"
};
function wrap(target) {
return new Proxy(target, {
*!*
/* your code */
*/!*
});
}
user = wrap(user);
alert(user.name); // John
*!*
alert(user.age); // ReferenceError: Property doesn't exist "age"
*/!*
```