debounce.js 343 B

12345678910111213141516171819
  1. var Debounce = (fn, t) => {
  2. let delay = t || 300;
  3. let timer;
  4. // console.log(fn)
  5. // console.log(typeof fn)
  6. return function () {
  7. let args = arguments;
  8. if(timer){
  9. clearTimeout(timer);
  10. }
  11. timer = setTimeout(() => {
  12. timer = null;
  13. fn.apply(this, args);
  14. }, delay);
  15. }
  16. };
  17. export default Debounce