-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDebounce.html
More file actions
42 lines (32 loc) · 750 Bytes
/
Copy pathDebounce.html
File metadata and controls
42 lines (32 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<html>
<body>
<input type="text" placeholder="type here" id="d">
</body>
<script>
// const URl = 'https://jsonplaceholder.typicode.com/posts'
// fetch (URl)
// .then(y => y.json())
// .then(y=>{
// console.log(y)
// return y
// })
// .then(y => console.log(y[0]))
function debounce(fun,delay){
let timeoutId
return function (...args){
if(timeoutId){
clearTimeout(timeoutId)
}
timeoutId = setTimeout(()=>{
fun.call(this,...args)
},delay)
}
}
const data = document.getElementById("d")
function finfSugg(){
console.log(data.value);
}
const decoFunc = debounce(finfSugg,500)
data.addEventListener("input",decoFunc)
</script>
</html>