> For the complete documentation index, see [llms.txt](https://easonwang.gitbook.io/web_advance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://easonwang.gitbook.io/web_advance/es6-es7-es8/es6-proxy.md).

# ES6 Proxy

可以改變原本預設的行為

```javascript
const person = {
  name: "Test"
};

const proxy = new Proxy(person, {
  get: function(target, propKey) {
    if (propKey in target) {
      return target[propKey];
    } else {
      throw new ReferenceError(`${propKey} do not exist.`);
    }
  }
});

proxy.name // "Test"
proxy.age // 出現自定義的錯誤，如果沒用 proxy 只會出現 undefined
```
