JavaScript Logo

JavaScript: Throttle utility function

function throttle(func, limit) { ⏎
	let inThrottle;

	return function() {
		const context = this;
		const args = arguments;

		if (!inThrottle) {
			func.apply(context, args);
			inThrottle = true;
			setTimeout(() => inThrottle = false, limit);
		}
	};
}
Accuracy
100 %
0 Mistakes
CPM
0
Average: 0 CPM
Time
0.000 s
Personal best: -.--- s