您的位置:首页 > 其它

underscore 的 debounce 的实现

2013-12-25 21:51 260 查看
[code]
debounce
_.debounce(function, wait, [immediate])

Creates>Pass true for>var lazyLayout = _.debounce(calculateLayout, 300);
$(window).resize(lazyLayout);[/code]

[code]

[code]_.debounce = function(func, wait, immediate) {
	var timeout;
	return function() {
		var context = this, args = arguments;
		var later = function() {
			timeout = null;
			if (!immediate) func.apply(context, args);
		};
		var callNow = immediate && !timeout;
		clearTimeout(timeout);
		timeout = setTimeout(later, wait);
		if (callNow) func.apply(context, args);
	};
};

[code]

[code]

[code]参考:http://underscorejs.org/

[code]http://davidwalsh.name/function-debounce
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: