Created
August 8, 2013 13:12
-
-
Save ivandotv/6184452 to your computer and use it in GitHub Desktop.
Javascript 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 myFunc = function (param) { | |
if (!myFunc.cache[param]) { | |
var result = {}; | |
// ... expensive operation ... | |
myFunc.cache[param] = result; | |
} | |
return myFunc.cache[param]; | |
}; | |
// cache storage | |
myFunc.cache = {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment