Last active
March 16, 2017 13:10
-
-
Save jtlindsey/ff5d5aa03e35f6e9befe11796ab58c4f to your computer and use it in GitHub Desktop.
Pass any function and its arguments using rest parameter syntax to function that repeats that function.
This file contains 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
/* | |
Sometimes i wan to run different functions multiple times without re-writing setInterval | |
and specifying speed, etc. This solution made that a little quicker. | |
*/ | |
const looper = (runCount, i, speed, logit, fn, ...args) => { | |
let r = () => { | |
if (i++ >= runCount) {clearTimeout(si)}; | |
logit ? console.log(fn(...args)) : fn(...args); | |
}; | |
let si = setInterval(r, speed); | |
}; | |
// runCount, 0, speed, logit, function, function_arg1, function_arg2, etc | |
looper(10, 0, 500, true, myfunction, "myfunction arg1"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment