Created
February 14, 2023 23:17
-
-
Save nuxodin/ae6b13c0f8c0d1c381b41c2b8605ba24 to your computer and use it in GitHub Desktop.
tryAgain 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
function tryAgain(fn, times = 2){ | |
try { | |
return fn(times); | |
} catch (e) { | |
if (times > 1) return tryAgain(fn, times-1); | |
throw e; | |
} | |
} | |
tryAgain( n => { | |
console.log(n+' trys left') | |
afsefesf(); | |
}, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment