JSFiddle - React, Tailwind, and code Playground

JavaScript

function adjustFunctionToCount(f){
    var count = 0;
    function newF(){
        count++;
        f.apply(this, arguments);
    }
    newF.getCount = function(){ return count; };
    return newF;
}

function handler(val){
    console.log('called with val ' + val);
}

handler = adjustFunctionToCount(handler);
handler('a');
handler('b');
console.log(handler.getCount());