There was an error while loading. Please reload this page.
1 parent 8cfaa78 commit d508bd6Copy full SHA for d508bd6
Example/Memento-Pattern.js
@@ -1 +1,21 @@
1
-// 备忘录模式(Memento Pattern)
+// 备忘录模式(Memento Pattern)
2
+
3
+let getPageData = (() => {
4
+ let cache = {}
5
+ return (page, fn) => {
6
+ if (cache[page]) {
7
+ // 已有指定缓存数据
8
+ fun && fn()
9
+ } else {
10
+ // 当前没有指定缓存数据
11
+ // 获取指定数据data
12
+ cache[page] = data
13
+ fn && fn()
14
+ }
15
16
17
+)()
18
19
+getPageData(1, () => {
20
+ // do somthing
21
+})
README.md
@@ -107,6 +107,10 @@
107
108
> [备忘录模式(Memento Pattern)](/Example/Memento-Pattern.js)
109
110
+ 定义:保存一个对象的某个状态,以便在适当的时候恢复对象。
111
+ 目的:在不破坏封装性的前提下,捕获一个对象的内部状态,并在该对象之外保存这个状态。
112
+ 场景:数据缓存。
113
114
> [迭代器模式(Iterator Pattern)](/Example/Iterator-Pattern.js)
115
116
> [命令模式(Command Pattern)](/Example/Command-Pattern.js)
0 commit comments