Last active
August 29, 2015 14:03
-
-
Save jasonrhodes/09ad69bff317544aefbd to your computer and use it in GitHub Desktop.
Creates a new function that will only run {{max}} number of times and then the function becomes a no-op pass-through
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
/** | |
* Creates a new function that will only run | |
* max number of times and then the function | |
* will become a no-op pass-through | |
* | |
* This could probably become its own little lib | |
* | |
* @param function func The main function | |
* @param int max | |
* @param int count optional starting point | |
* | |
* @return function | |
*/ | |
function times(func, max, count) { | |
count = count || 0; | |
return function () { | |
if (count < max) { | |
count += 1; | |
return func.apply(this, arguments); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment