Skip to content

Instantly share code, notes, and snippets.

@oliger
Created October 8, 2012 10:35
Show Gist options
  • Save oliger/3851881 to your computer and use it in GitHub Desktop.
Save oliger/3851881 to your computer and use it in GitHub Desktop.
Simple javascript memoizer
function memoize(fn, hasher) {
hasher = hasher || JSON.stringify;
var memo = {};
return function() {
var key = hasher(arguments);
return (key in memo) ? memo[key] : memo[key] = fn.apply(this, arguments);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment