Skip to content

Instantly share code, notes, and snippets.

@BytefishMedium
Created November 25, 2021 07:07
Show Gist options
  • Save BytefishMedium/aefce26ca7b76cb2d088e7d5c4950b3e to your computer and use it in GitHub Desktop.
Save BytefishMedium/aefce26ca7b76cb2d088e7d5c4950b3e to your computer and use it in GitHub Desktop.
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