SoFunction
Updated on 2025-04-10

Javascript Memoization cache function usage instructions


var Memoize = function(fn, cache, refetch, obj){
cache = cache || {};// Used to cache the results
return function(){
var k = arguments[1] ? (arguments, '__') : arguments[0];//There are multiple parameters separated by '__'
if (!(k in cache) || (refetch && cache[k] == refetch)) { //If it is not in the cache list and is equal to the given refetch value, re-operate
cache[k] = (obj || fn, arguments); //obj parameter can be used to change this pointer
}
return cache[k];//Return result
}
}