Quick actions

cmd+k|ctrl+k

Navigation

Languages

Debounce Example

Snippet info

Language

JavaScript

Visibility

public

Author

poetril

Created

2022-06-07T13:34:36.114882Z

Updated

2022-06-07T13:47:48.797473Z

function debounce(fn, delay) {
    let timer; 
    return function(...args) {
        clearTimeout(timer)
        
        setTimeout(() => {
           fn(args) 
        }, delay)
    }
}

let test = debounce(() => console.log('hello'), 1000)
let testTwo = debounce(() => console.log('hello two', 500))
test()
testTwo()
INFO