Skip to content

Instantly share code, notes, and snippets.

@ardeshireshghi
Created April 28, 2016 15:57
Show Gist options
  • Save ardeshireshghi/59365ec882f94c8a74292fc9392a10fb to your computer and use it in GitHub Desktop.
Save ardeshireshghi/59365ec882f94c8a74292fc9392a10fb to your computer and use it in GitHub Desktop.
Be able to call a function limited number of times
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