react-lite-misc
Version:
Misc Components of jianliao.com
27 lines (24 loc) • 620 B
JavaScript
(function() {
var slice = [].slice;
module.exports = function(func, threshold, execAsap) {
var timeout;
timeout = null;
return function() {
var args, delayed, obj;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
obj = this;
delayed = function() {
if (!execAsap) {
func.apply(obj, args);
}
return timeout = null;
};
if (timeout) {
clearTimeout(timeout);
} else if (execAsap) {
func.apply(obj, args);
}
return timeout = setTimeout(delayed, threshold || 100);
};
};
}).call(this);