We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b23d987 commit f07d852Copy full SHA for f07d852
src/structural/proxy/Sample-2.js
@@ -0,0 +1,19 @@
1
+// proxy cache【缓存代理】
2
+
3
+const multiply = function(...args) {
4
+ console.log("You can' see me if args in cache")
5
+ return args.reduce((product, n) => product * n, 1)
6
+}
7
8
+const proxyMultiply = (function() {
9
+ const cache = {}
10
+ return function() {
11
+ const argsKey = Array.prototype.join.call(arguments, '@')
12
+ if (argsKey in cache) return cache[argsKey]
13
+ return (cache[argsKey] = multiply(...arguments))
14
+ }
15
+})()
16
17
+console.log(proxyMultiply(3, 4))
18
19
+console.log(proxyMultiply(5, 4))
0 commit comments