Skip to content

Instantly share code, notes, and snippets.

@cafedomingo
Created October 15, 2010 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cafedomingo/629083 to your computer and use it in GitHub Desktop.
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.
runOnce = function( func ) {
return ( function() {
var hasRun = false;
return function() {
if ( !hasRun )
{
hasRun = true;
func.apply( this, arguments );
}
};
})();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment