_.memoize = function(func) { var cached = {}; return function() { var args = Array.prototype.slice.call(arguments); if (cached[args]) { console.log('returning cached'); return cached[args]; } else { cached[args] = func.apply(this, args); return cached[args]; } }; }; _.memoize = function(func) { var cached = {}; return function() { if (cached[arguments]) { console.log('returning cached'); return cached[arguments]; } else { cached[arguments] = func.apply(this, arguments); return cached[arguments]; } }; }; var add = function(a, b) { return a + b; }; var memoAdd = _.memoize(add); memoAdd(1, 2) => 3; memoAdd(3, 4) 'returning cached' => 3; ???? Why does the second memoize implementation not work without the Array.prototype.slice.call?
is the bracket notation actually stringifying the word arguments as a key instead of the actual real arguments?