خرید بک لینک

Vote count: 0

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 = {};
retu function () {
    var key = [].join.call(arguments, '§') + '§';
    if (key in cache) {
        retu cache[key];        }
    retu cache[key] = fn.apply(this, arguments);
  };
};

and its execution

 var foo = 1;
function bar(baz) {
    retu 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

asked 46 secs ago

- - , .

برچسب: نویسنده: استخدام کار تاريخ: يکشنبه 16 اسفند 1394 ساعت: 17:17

صفحه بندی