Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kubarskii/64463c97b73180249b2f0b0fcdee0d39 to your computer and use it in GitHub Desktop.
Save kubarskii/64463c97b73180249b2f0b0fcdee0d39 to your computer and use it in GitHub Desktop.
Memo function
const memo = (function () {
const cache = new Map()
return function (fn, ctx = null, ...params) {
if (cache.has([fn, params, ctx].toString())) {
return cache.get([fn, params, ctx].toString())
} else {
const res = fn.call(ctx, ...params);
cache.set([fn, params, ctx].toString(), res);
return res;
}
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment