Skip to content

Instantly share code, notes, and snippets.

@kana
Created June 26, 2013 14:57
Show Gist options
  • Save kana/5868059 to your computer and use it in GitHub Desktop.
Save kana/5868059 to your computer and use it in GitHub Desktop.
Generic memoization in JavaScript?
function memoize(f) {
var memo = {};
return function () {
var key = JSON.stringify(arguments);
if (memo[key] === undefined)
memo[key] = f.apply(this, arguments);
return memo[key];
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment