Skip to content

Commit

Permalink
add proxy-pattern md
Browse files Browse the repository at this point in the history
  • Loading branch information
Xicheng Guo committed Jul 24, 2024
1 parent 6c0c5cb commit 9873077
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/.vitepress/sidebars/ecma-script.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,23 @@
link: /javascript/ecma-script/proxy-and-reflect/reflect#直接使用反射
- text: 代理捕获器中使用反射
link: /javascript/ecma-script/proxy-and-reflect/reflect#代理捕获器中使用反射
- text: 代理模式
link: /javascript/ecma-script/proxy-and-reflect/proxy-pattern
items:
- text: 跟踪属性访问
link: /javascript/ecma-script/proxy-and-reflect/proxy-pattern#跟踪属性访问
- text: 隐藏属性
link: /javascript/ecma-script/proxy-and-reflect/proxy-pattern#隐藏属性
- text: 属性验证
link: /javascript/ecma-script/proxy-and-reflect/proxy-pattern#属性验证
- text: 函数参数验证
link: /javascript/ecma-script/proxy-and-reflect/proxy-pattern#函数参数验证
- text: 构造函数参数验证
link: /javascript/ecma-script/proxy-and-reflect/proxy-pattern#构造函数参数验证
- text: 数据绑定
link: /javascript/ecma-script/proxy-and-reflect/proxy-pattern#数据绑定
- text: 可观察对象
link: /javascript/ecma-script/proxy-and-reflect/proxy-pattern#可观察对象
- text: 模块
collapsed: true
items:
Expand Down
2 changes: 2 additions & 0 deletions src/.vitepress/sidebars/vue.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- text: Vue
items:
- text: 模版语法
collapsed: true
items:
- text: 插值表达式
link: /frontend/vue/template-syntax/interpolation
Expand Down Expand Up @@ -50,6 +51,7 @@
- text: v-for 与 v-if
link: /frontend/vue/template-syntax/list-rendering#v-for-与-v-if
- text: 表单
collapsed: true
items:
- text: 双向绑定
link: /frontend/vue/form/two-way-binding
Expand Down
35 changes: 35 additions & 0 deletions src/javascript/ecma-script/proxy-and-reflect/proxy-pattern.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 代理模式

## 跟踪属性访问

通过捕获`get``set``has` 等操作,可以知道对象属性在何时何处被访问。

<<< @/../projects/javascript-sandbox/src/proxy-and-reflect/proxy-pattern.ts#trace-attribute

## 隐藏属性

代理的内部实现对外部实现不可见,因此可以隐藏对象的属性。

<<< @/../projects/javascript-sandbox/src/proxy-and-reflect/proxy-pattern.ts#hidden-attribute

## 属性验证

所有的赋值操作都会触发 `set` 捕获器,因此可以根据情况决定允许赋值或拒绝赋值。

<<< @/../projects/javascript-sandbox/src/proxy-and-reflect/proxy-pattern.ts#validate-attribute

## 函数参数验证

<<< @/../projects/javascript-sandbox/src/proxy-and-reflect/proxy-pattern.ts#validate-function-parameter

## 构造函数参数验证

<<< @/../projects/javascript-sandbox/src/proxy-and-reflect/proxy-pattern.ts#validate-constructor-parameter

## 数据绑定

<<< @/../projects/javascript-sandbox/src/proxy-and-reflect/proxy-pattern.ts#data-binding

## 可观察对象

<<< @/../projects/javascript-sandbox/src/proxy-and-reflect/proxy-pattern.ts#observable-object

0 comments on commit 9873077

Please sign in to comment.