JSFiddle - React, Tailwind, and code Playground
JavaScript
function spy(func) {
var report = { totalCalls: 0 };
function spied(){
var args = Array.prototype.slice.call(arguments);
report.totalCalls++;
return func.apply(this, args);
}
spied.report = function() {
return report;
}
return spied;
}
var spied = spy(function(){});
var report = spied.report();
spied();
spied();
spied();
console.log(report.totalCalls);