MCPcopy
hub / github.com/stemkoski/stemkoski.github.com / memoize

Function memoize

MathBox/mathbox-bundle.js:40693–40707  ·  view source on GitHub ↗

* Creates a function that memoizes the result of `func`. If `resolver` is * provided it will be used to determine the cache key for storing the result * based on the arguments provided to the memoized function. By default, the * first argument provided to the memoized function is used

(func, resolver)

Source from the content-addressed store, hash-verified

40691 * // => { 'name': 'penelope', 'age': 1 }
40692 */
40693 function memoize(func, resolver) {
40694 if (!isFunction(func)) {
40695 throw new TypeError;
40696 }
40697 var memoized = function() {
40698 var cache = memoized.cache,
40699 key = resolver ? resolver.apply(this, arguments) : keyPrefix + arguments[0];
40700
40701 return hasOwnProperty.call(cache, key)
40702 ? cache[key]
40703 : (cache[key] = func.apply(this, arguments));
40704 }
40705 memoized.cache = {};
40706 return memoized;
40707 }
40708
40709 /**
40710 * Creates a function that is restricted to execute `func` once. Repeat calls to

Callers

nothing calls this directly

Calls 1

isFunctionFunction · 0.70

Tested by

no test coverage detected