#1882·es-toolkit

[function][memoize] should accept multiple parameters

Author: kaitoukid-1412Created Jul 12, 2026Updated Jul 15, 2026

https://github.com/toss/es-toolkit/blob/171d8a8a5941671d3b8e99ba617bfb27cf2c71b3/src/function/memoize.ts#L82

hotfix

javascript




function memoize(fn, options = {}) {
  const { cache = new Map(), getCacheKey } = options

  const memoizedFn = function(...args) {
    const key = getCacheKey ? getCacheKey(...args) : JSON.stringify(args) // ?

    if (cache.has(key)) {
      return cache.get(key)
    }

    const result = fn.call(this, ...args)

    cache.set(key, result)

    return result
  }

  memoizedFn.cache = cache

  return memoizedFn
}

 memoize(console.log)(1,2,3)