Skip to content

Instantly share code, notes, and snippets.

@psiborg
Created January 6, 2012 08:15
Show Gist options
  • Save psiborg/1569638 to your computer and use it in GitHub Desktop.
Save psiborg/1569638 to your computer and use it in GitHub Desktop.
JS Memoization
var getElement = function () {
console.log("Creating element");
var elem = document.createElement("div");
// do a bunch of expensive operations
// overwrite function with a simpler version
getElement = function () {
return elem;
};
return elem;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment