We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5393526 commit d7c81ccCopy full SHA for d7c81cc
README.md
@@ -33,6 +33,7 @@
33
- [函数节流](./src/throttle.js) ★★★
34
- [函数柯里化(实现 `sum(1,2)(3)()`)](./src/curry.js) ★★★
35
- [compose 函数](./src/compose.js) ★★
36
+- [before 函数](./src/before.js) ★
37
38
39
## 数组
src/before.js
@@ -0,0 +1,24 @@
1
+/**
2
+ * 传入任意一个函数,只能调用指定的次数
3
+ * @param {*} count 调用次数
4
+ * @param {*} func 传入函数
5
+ * @returns
6
+ */
7
+ function before(count, func) {
8
+ var temp = count;
9
+ return function() {
10
+ if (temp > 1) {
11
+ temp--;
12
+ const args = [...arguments];
13
+ func.apply(this, args);
14
+ }
15
16
+}
17
+
18
+const log = a => console.log(a);
19
20
+const log3 = before(3, log);
21
22
+log3(2);
23
+log3(1);
24
+log3(3);
0 commit comments