JS Debounce Throttle
Ringkasan
Debounce & throttle membatasi seberapa sering fungsi jalan — penting untuk resize/scroll/input event.
Konsep Dasar
- Debounce: jalankan hanya setelah aktivitas berhenti
Nms (contoh: search-as-you-type). - Throttle: jalankan maksimal 1x per
Nms (contoh: scroll handler). - Keduanya cegah jank & request berlebih.
Cara Kerja / Struktur
function debounce(fn, ms){
let t; return (...a)=>{ clearTimeout(t); t=setTimeout(()=>fn