Js stabilization

Add a delay device before the user input and send the request a few milliseconds after the user input. Only the user input last time, simple optimization of the code, can achieve the goal below

	function debounce(fn, time) {
		let _arguments = arguments
		let timeout = null
		return function() {
			if (timeout) {
				clearTimeout(timeout)
			}
			timeout = setTimeout(() => {
				fn.call(this, _arguments)
			}, time);
		}
	}
Copy the code

Js throttling

Controls the execution times of high frequency events

var throttle = function(func, delay) { var timer = null; return function() { var context = this; var args = arguments; if (! timer) { timer = setTimeout(function() { func.apply(context, args); timer = null; }, delay); }}}Copy the code