function debounce(callback, delay) {
let timer;
return function (...args) {
console.log('Новый вызов');
clearTimeout(timer);
timer = setTimeout(() => {
callback.apply(this, args);
}, delay);
};
}
function search(query) {
console.log('🚀 Запрос на сервер:', query);
}
const debouncedSearch = debounce(search, 1000);
debouncedSearch('r');
setTimeout(() => {
debouncedSearch('re');
}, 300);
setTimeout(() => {
debouncedSearch('rea');
}, 600);
setTimeout(() => {
debouncedSearch('react');
}, 900);
setTimeout(() => {
debouncedSearch('rea');
}, 600);
Code will run automatically after changes.
Code runs in an isolated environment.
Code runs in an isolated environment.