| 12345678910111213141516171819202122232425262728293031323334 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <script>
- // proxy 代理 在对象外面包了一层拦截器
- // const xxx = new Proxy(目标对象,拦截器)
- const obj = { name: "图图", age: 3 };
- const newProxy1 = new Proxy(obj, {
- get(target,key) {
- console.log(target,'target');
- console.log(key,'key')
- return target[key]
- },
- set(target,key,value) {
- console.log(target,'target1');
- console.log(key,'key1')
- console.log(value,'value1');
- target[key] = value;
- return true;
- }
- });
- newProxy1.name = '喜羊羊';
- console.log(newProxy1.name)
- </script>
- </body>
- </html>
|