Skip to content

Instantly share code, notes, and snippets.

@jonastemplestein
Created September 6, 2010 10:23
Show Gist options
  • Save jonastemplestein/566881 to your computer and use it in GitHub Desktop.
Save jonastemplestein/566881 to your computer and use it in GitHub Desktop.
I use this for Jake dependencies that only need to run once.
/**
* makes sure a function is only executed once
* all future runs of the function return the same result instantly
* I use this for Jakefiles where tasks should not run twice as dependencies
*
* by @jonashuckestein
*/
var once = function(fn) {
var self = this;
var ran_once = false;
var result = undefined;
return function() {
if (ran_once == false) {
result = fn.apply(self, arguments);
ran_once = true;
}
return result;
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment