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
相关文章推荐
- underscore 源码解读之 bind 方法的实现
- underscore 函数去抖的实现 #21
- underscore里面的debounce与throttle
- angular.js和vue.js中实现函数去抖示例(debounce)
- C#.Net下的防抖-Debounce和节流阀-Throttle功能实现
- RxJava实例-用debounce实现的简单即时搜索
- underscore方法--debounce
- Debounce 和 Throttle 的原理及实现
- debounce与throttle实现与原理
- 利用throttle和debounce实现延迟请求
- throttle和debounce简单实现
- underscore 的debounce
- Debounce 和 Throttle 的原理及实现
- 用C#实现汉字转化为拼音
- 无崩溃(VB IDE)子类技术实现
- 用ASP实现论坛的UBB功能
- sql实现10进制转16进制(转)
- 常见设计模式的解析和实现(C++)之七-Bridge模式
- javascript实现的LI列表输出,隔行同色的代码
- 在SVN中实现$Id$的自动替换