After reading this several times, I still do not understand how this sample code from page 76 Stoyan Stefanov "JavaScript Templates" works. I'm not a ninja yet. But for me, it reads as if it were storing an empty object:
var myFunc = function (param) {
if (!myFunc.cache[param]) {
var result = {};
myFunc.cache[param] = result;
}
return myFunc.cache[param];
};
myFunc.cache = {};
If this invisible “expensive operation” does not return to result, I see nothing.
Where are the results stored?
PS: I read Caching Result Function Returns from John Resig Learning Advanced JavaScript , which is a similar exercise, and I get it. But here the code is different.
source
share