mirror of
https://github.com/videojs/video.js.git
synced 2025-01-02 06:32:07 +02:00
Refactor throttle in utils/fn.js
This commit is contained in:
parent
4c938e07e9
commit
dee5402aa5
@ -60,19 +60,15 @@ export const bind_ = function(context, fn, uid) {
|
||||
*
|
||||
* @return {Function}
|
||||
*/
|
||||
export const throttle = function(fn, wait) {
|
||||
let last = window.performance.now();
|
||||
|
||||
const throttled = function(...args) {
|
||||
const now = window.performance.now();
|
||||
|
||||
if (now - last >= wait) {
|
||||
fn(...args);
|
||||
last = now;
|
||||
export const throttle = function(func, delay) {
|
||||
let lastCallTime = 0;
|
||||
return function throttled(...args) {
|
||||
const currentTime = Date.now()
|
||||
if (currentTime - lastCallTime >= delay) {
|
||||
lastCallTime = currentTime;
|
||||
func(...args);
|
||||
}
|
||||
};
|
||||
|
||||
return throttled;
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user