debounce = ( fn, time ) => {
let timerId;
return ( ...args ) => {
if ( timerId ) {
clearTimeout( timerId );
}
timerId = setTimeout( () => {
fn( ...args );
timerId = null;
}, time );
};
},
debounce( () => {
//какой-либо код
} )();
const debounce = ( fn, time ) => {
let timerId;
return ( ...args ) => {
if ( timerId ) {
clearTimeout( timerId );
}
timerId = setTimeout( () => {
fn( ...args );
timerId = null;
}, time );
};
}
const fn = (arg) => {
console.log(arg)
}
const debouncedFn = debounce(fn, 250)
let i = 0
debouncedFn(++i)
debouncedFn(++i)
debouncedFn(++i)
debouncedFn(++i)