I have recently read tutorial associated with JavaScript from this page, I tried some piece of code but i didn't understand some logic. Below is author code.
function itself:
var lz="";
lz.memo = function (fn) {
var cache = {};
return function () {
var key = [].join.call(arguments, '§') + '§';
if (key in cache) {
return cache[key]; }
return cache[key] = fn.apply(this, arguments);
};
};
and its execution
var foo = 1;
function bar(baz) {
return baz + foo;
}
var cached = lz.memo(bar);
console.log(cached(1));
foo += 1;
console.log(cached(1)); //2
But if I change
var key = [].join.call(arguments, '§') + '§';
to
var key=arguments[0];
it also works (Caching works). What is the purpose here the author used
var key = [].join.call(arguments, '§') + '§';
Thank for attention! Here is CODEPEN of code