Arrow functions create problems in memoization

by Mohan Pierce   Last Updated July 11, 2018 19:05 PM

Memoization

function memoize(fn) {
    var cache = {};
    return () => {
        var key = arguments.length + Array.prototype.join.call(arguments, ",");
        if (key in cache) {
            return cache[key];
        } else {
            return cache[key] = fn.apply(this, arguments);
        }
    }
};

So when i memoize a function it never gives me the output return value instead returns the function itself we memoized if i change line 3 arrow function to a normal function everything works fine whats happening here?

Tags : javascript


Related Questions


How to use SWIG's Javascript support on Windows

Updated September 22, 2017 04:05 AM


Reach <a> tag in iframe

Updated April 04, 2015 15:02 PM


How much should I be using 'let' vs 'const' in ES6?

Updated April 09, 2015 19:02 PM