面试之手写防抖节流 (9)

简单版本

function throttle(fn, wait = 1000) { let previous = 0; const throttled = (...args) => { const now = +new Date(); if (now - previous > wait) { fn.apply(this, args); previous = now; } }; return throttled; }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wsfjds.html