JavaScript

Debounce & throttle

Në shqip përdoret i njëjti emër.

ShpjegimiSQ

Debounce pret derisa përdoruesi të ndalojë për një moment (p.sh. 300 ms pa shtypur) para se ta ekzekutojë funksionin — ideal për kërkimin ndërsa shkruan. Throttle e lejon funksionin të ekzekutohet maksimumi një herë në një interval — ideal për scroll.

EnglishEN

Debounce waits until the user pauses for a moment (e.g. 300 ms without typing) before running the function — perfect for search-as-you-type. Throttle lets the function run at most once per interval — perfect for scrolling.

Si ta mendosh

Debounce është si ashensori që pret disa sekonda pasi hyn i fundit para se të nisë; throttle është si autobusi që niset çdo 15 minuta, sido që të vijnë pasagjerët.

Lexoje në anglisht

Debounce is like a lift that waits a few seconds after the last person gets in before moving; throttle is like a bus that leaves every 15 minutes, however people arrive.

Shembull kodijavascript

let kohemates;
kerkimi.addEventListener("input", () => {
  clearTimeout(kohemates);
  kohemates = setTimeout(kerko, 300);
});

Terma të lidhur