31 lines
567 B
Markdown
31 lines
567 B
Markdown
|
|
# Error on reading non-existant property
|
|
|
|
Create a proxy that throws an error for an attempt to read of a non-existant property.
|
|
|
|
That can help to detect programming mistakes early.
|
|
|
|
Write a function `wrap(target)` that takes an object `target` and return a proxy instead with that functionality.
|
|
|
|
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); // Error: Property doesn't exist
|
|
*/!*
|
|
```
|