Created
November 25, 2021 07:07
-
-
Save BytefishMedium/aefce26ca7b76cb2d088e7d5c4950b3e to your computer and use it in GitHub Desktop.
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 once(func) { | |
let hasExecuted = false; | |
let result; | |
return function () { | |
if (hasExecuted) return result; | |
hasExecuted = true; | |
result = func.apply(this, arguments); | |
func = null; | |
return result; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment