// 防抖 function debounce(fn, delay) { let timeout = null; return function() { clearTimeout(timeout); timeout = setTimeout(() => { fn.apply(this, arguments) }, delay) } }
// 节流 function throttle(fn, delay) { let run = true; // 开关 return function() { if (!run) { return } run = false setTimeout(() => { fn.apply(this, arguments); run = true; }, delay); } }
// throttle(printPos(), 1000);