延时执行

 1 var delayRun = function(fn, interval) {
 2     var timer = null;
 3     return function() {
 4         var that = this;
 5         var args = Array.prototype.slice(arguments, 0);
 6         if (timer === null) {
 7             fn.apply(that, args);
 8             timer = setTimeout(function() {
 9                 clearTimeout(timer);
10                 timer = null;
11             }, interval || 500);
12         }
13     };
14 };

 

posted @ 2020-06-11 11:44  xlsdg  阅读(80)  评论(0)    收藏  举报