throttle.js 252 B

123456789101112
  1. const timeKey = {}
  2. export default{
  3. call(callback, label = 'throttle') {
  4. let now = new Date().getTime()
  5. let time = timeKey[label]
  6. if (time && now - time <= 500) return
  7. timeKey[label] = now
  8. callback()
  9. }
  10. }