I was following the node functional programing tutorial in here, but when I tried implement my code for lesson # 12 as follow
function Spy(target, method) {
var store={};
var self=this;
var copy=target[method];
store[target[method]]=0;
console.log(store);
console.log(store[target[method]]);
target[method]=function(){
store[target[method]]+=1;
return copy.apply(this,arguments);
};
return {count:store[target[method]]};
}
var spy = Spy(console, 'error');
console.error('calling console.error');
console.error('calling console.error');
console.error('calling console.error');
console.log(spy.count);
I got the console.log(store)
within Spy return an object containing a function. Also, the final return return {count:store[target[method]]};
from Spy return undefined. Can anyone please explain the reasons behind these two? Thanks