throttle.js 320 B

1234567891011121314
  1. /* eslint-disable prefer-rest-params */
  2. export default function throttle(func, delay) {
  3. let prev = Date.now();
  4. return function () {
  5. const context = this;
  6. const args = arguments;
  7. const now = Date.now();
  8. if (now - prev >= delay) {
  9. func.apply(context, args);
  10. prev = Date.now();
  11. }
  12. };
  13. }