hszy00232/developExperience

函数延时执行

Opened this issue · 0 comments

/**
 * @param  {[type]} functor [函子]
 * @param  {[type]} wait    [延迟时间]
 * @return {[type]}         [延迟wait时间执行一次functor]
 */
function throttle(functor, wait){
	var timer = null;
	return function() {
		var _args = [].slice.call(arguments);
		if(!timer){
			timer = setTimeout(function() {
				timer = null;
			}, wait);
			return functor.apply(this, _args);
		}
	}
}