Last active
August 29, 2015 14:23
-
-
Save think2011/ac620d4e517f3105f7bf to your computer and use it in GitHub Desktop.
间隔执行fn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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