Skip to content

Instantly share code, notes, and snippets.

@sebinsua
Created Aug 3, 2022
Embed
What would you like to do?
function maxCall1(fn, n) {
let count = 0;
return function withMaxCall(...args) {
if (count + 1 > n) {
return;
}
count++;
return fn(...args);
};
}
function maxCall2(fn, n) {
function withMaxCall(...args) {
withMaxCall.callCount++;
if (withMaxCall.callCount > n) {
return;
}
return fn(...args);
}
withMaxCall.callCount = 0;
return withMaxCall;
}
function helloWorld() {
console.log("hello world!");
}
const fn = maxCall2(helloWorld, 5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment