Created
September 6, 2010 10:23
-
-
Save jonastemplestein/566881 to your computer and use it in GitHub Desktop.
I use this for Jake dependencies that only need to run once.
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
/** | |
* 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