Created
April 28, 2016 15:57
-
-
Save ardeshireshghi/59365ec882f94c8a74292fc9392a10fb to your computer and use it in GitHub Desktop.
Be able to call a function limited number of times
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
function limitCalls(fn, maxCall) { | |
if (!fn.called) { | |
fn.called = 0; | |
} | |
return function() { | |
if (fn.called < maxCall) { | |
fn.called++; | |
return fn.apply(null, arguments); | |
} | |
}; | |
} | |
module.exports = limitCalls; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment