Last active
March 26, 2026 00:35
-
-
Save cafedomingo/629083 to your computer and use it in GitHub Desktop.
Takes a function and returns a function that will only be run once.
This file contains hidden or 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
| const runOnce = function(func) { | |
| let hasRun = false; | |
| let result; | |
| return function(...args) { | |
| if (!hasRun) { | |
| hasRun = true; | |
| result = func.apply(this, args); | |
| } | |
| return result; | |
| }; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment