Skip to content

Instantly share code, notes, and snippets.

@kpuputti
Created June 16, 2011 13:52
Show Gist options
  • Save kpuputti/1029264 to your computer and use it in GitHub Desktop.
Save kpuputti/1029264 to your computer and use it in GitHub Desktop.
Lazy initialization for a function
var lazy = (function () {
var initialized = false;
var init = function () {
// init code here
};
return function () {
if (!initialized) {
init();
initialized = true;
}
// other functionality here
};
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment