1. const memoize = fn => new Proxy(fn, {
    2. cache: new Map(),
    3. apply (target, thisArg, argsList) {
    4. let cacheKey = argsList.toString();
    5. if(!this.cache.has(cacheKey))
    6. this.cache.set(cacheKey, target.apply(thisArg, argsList));
    7. return this.cache.get(cacheKey);
    8. }
    9. });
    10. const fibonacci = n => (n <= 1 ? 1 : fibonacci(n - 1) + fibonacci(n - 2));
    11. const memoizedFibonacci = memoize(fibonacci);
    12. for (let i = 0; i < 100; i ++)
    13. fibonacci(30); // ~5000ms
    14. for (let i = 0; i < 100; i ++)
    15. memoizedFibonacci(30); // ~50ms