Skip to content

Instantly share code, notes, and snippets.

@ivandotv
Created August 8, 2013 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivandotv/6184452 to your computer and use it in GitHub Desktop.
Save ivandotv/6184452 to your computer and use it in GitHub Desktop.
Javascript memoization
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