1
0
mirror of https://github.com/videojs/video.js.git synced 2025-07-13 01:30:17 +02:00

Refactor throttle in utils/fn.js

This commit is contained in:
Ahmed Saber
2023-07-15 03:04:41 +03:00
parent 4c938e07e9
commit dee5402aa5

View File

@ -60,19 +60,15 @@ export const bind_ = function(context, fn, uid) {
* *
* @return {Function} * @return {Function}
*/ */
export const throttle = function(fn, wait) { export const throttle = function(func, delay) {
let last = window.performance.now(); let lastCallTime = 0;
return function throttled(...args) {
const throttled = function(...args) { const currentTime = Date.now()
const now = window.performance.now(); if (currentTime - lastCallTime >= delay) {
lastCallTime = currentTime;
if (now - last >= wait) { func(...args);
fn(...args);
last = now;
} }
}; };
return throttled;
}; };
/** /**