(func, time)
| 48 | } |
| 49 | |
| 50 | export function throttle(func, time) { |
| 51 | let lastTime = 0; |
| 52 | time = Math.max(0, +time || 0); |
| 53 | function throttledFunction(...args) { |
| 54 | const now = performance.now(); |
| 55 | if (lastTime + time < now) { |
| 56 | lastTime = now; |
| 57 | func.apply(this, args); |
| 58 | } |
| 59 | } |
| 60 | return throttledFunction; |
| 61 | } |
| 62 | |
| 63 | export function noop() {} |
| 64 |