加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
debounce.js 923 Bytes
一键复制 编辑 原始数据 按行查看 历史
define([], function(){
// module:
// dojo/debounce
// summary:
// This module provide a debouncer
return function(cb, wait){
// summary:
// Create a function that will only execute after `wait` milliseconds
// description:
// Create a function that will only execute after `wait` milliseconds
// of repeated execution. Useful for delaying some event action slightly to allow
// for rapidly-firing events such as window.resize, node.mousemove and so on.
// cb: Function
// A callback to fire. Like hitch() and partial(), arguments passed to the
// returned function curry along to the original callback.
// wait: Integer
// Time to spend caching executions before actually executing.
var timer;
return function(){
if(timer){
clearTimeout(timer);
}
var self = this;
var a = arguments;
timer = setTimeout(function(){
cb.apply(self, a);
}, wait);
};
};
});
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化