Skip to content

Instantly share code, notes, and snippets.

@cafedomingo
Last active October 18, 2026 06:10
Show Gist options
  • Select an option

  • Save cafedomingo/629083 to your computer and use it in GitHub Desktop.

Select an option

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.
const runOnce = function(func) {
let result;
return function(...args) {
if (func) {
const f = func;
func = undefined;
result = f.apply(this, args);
}
return result;
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment