debounce
Creates a debounced function that delays invoking the listener until after a specified delay.
debounce(listener, delay)
debounce(listener, delay)
Creates a debounced function that delays invoking the listener until after a specified delay.
Parameters:
listener
: The function to execute after the delay.delay
: The time (in milliseconds) to wait before executing the function.
Usage:
window.addEventListener('resize', debounce(() => console.log('Triggered!'),3000));
$('#myinput').on('change',debounce(function(){
//this code here will run after 5 seconds
console.log('changes saved!!')
},5000))
('#myinput').click(debounce(function(){
//this code here will run after 5 seconds
console.log('changes saved!!')
},5000))
('#myinput').on('input',(debounce(function(){
//this code here will run after 10 seconds
console.log('changes saved!!')
},10000))
Last updated