Created
January 6, 2012 08:15
-
-
Save psiborg/1569638 to your computer and use it in GitHub Desktop.
JS Memoization
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
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