Skip to content

Instantly share code, notes, and snippets.

@bjdixon
Last active August 29, 2015 14:26
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 bjdixon/34048baad52d60c3ed8c to your computer and use it in GitHub Desktop.
Save bjdixon/34048baad52d60c3ed8c to your computer and use it in GitHub Desktop.
Memoize a function
memo = function (fn) {
var cache = {};
return function () {
var key = JSON.stringify(this, arguments);
return cache[key] || (cache[key] = fn.apply(this, arguments));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment