JSFiddle - React, Tailwind, and code Playground

JavaScript

function spy(func) {
    function spied(){
        var args = Array.prototype.slice.call(arguments);
        spied.totalCalls++;
        return func.apply(this, args);
    }
    spied.totalCalls = 0;
    return spied;
}


var spied = spy(function(){});

spied();
spied();
spied();

console.log(spied.totalCalls);