This commit is contained in:
PinkR1ver 2024-03-27 20:46:23 +08:00
parent fa2d5d81a6
commit e22937cb41

View File

@ -114,3 +114,25 @@ const proxy = new Proxy(user, handler);
console.log(proxy.age); // 成功
console.log(proxy.salary); // undefined
```
## 日志记录
```js
const object = {
"num": 1,
"str": "Hello World",
"obj": {
"x": 5
}
};
const proxiedObject = new Proxy(object, {
get: (target, key) => {
console.log("Accessing", key);
return target[key];
}
});
proxiedObject.num; // 打印: Accessing num
```