Skip to content

Instantly share code, notes, and snippets.

@think2011
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save think2011/ac620d4e517f3105f7bf to your computer and use it in GitHub Desktop.
Save think2011/ac620d4e517f3105f7bf to your computer and use it in GitHub Desktop.
间隔执行fn
fnInterval(5, 1000, function (index) {
console.log(index);
});
/**
* 间隔执行fn
* @param {number} time 次数
* @param {number} delay 间隔毫秒
* @param {Function} fn fn(index) index从1开始
*/
function fnInterval (time, delay, fn) {
var index = 1;
var interval = setInterval(function () {
fn(index);
index === time ? clearInterval(interval) : index++;
}, delay);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment