We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 67dc68d commit df827b0Copy full SHA for df827b0
front-end-interview/debounce.js
front-end-interview/debounce.ts
@@ -0,0 +1,14 @@
1
+/**
2
+ * 防抖
3
+ * @param fn
4
+ * @param delay
5
+ */
6
+const de = function (fn: Function, delay: number = 100) {
7
+ let timer: number;
8
+ return (...args: []) => {
9
+ clearTimeout(timer);
10
+ timer = setTimeout(() => {
11
+ fn.apply(this, args);
12
+ }, delay)
13
+ }
14
+}
front-end-interview/throttle.js
front-end-interview/throttle.ts
@@ -0,0 +1,18 @@
+const th = function (fn: Function, delay: number = 100) {
+ let flag = true;
+ if (!flag) {
+ return;
+ flag = false;
+ setTimeout(() => {
15
+ flag = true;
16
17
18
0 commit comments