How can I make this js script so that it doesn’t use eval?

I have this code

var clsStopwatch = function() {
        var startAt = 0;
        var lapTime = 0;    

        var now = function() {
                return (new Date()).getTime(); 
            }; 
 
        this.start = function() {
                startAt = startAt ? startAt : now();
            };

        this.stop = function() {
                lapTime = startAt ? lapTime + now() - startAt : lapTime;
                startAt = 0;
            };

        // Reset
        this.reset = function() {
                lapTime = startAt = 0;
            };

        // Duration
        this.time = function() {
                return lapTime + (startAt ? now() - startAt : 0); 
            };
    };

var x = new clsStopwatch();
var $time;
var clocktimer;

function pad(num, size) {
    var s = "0000" + num;
    return s.substr(s.length - size);
}

function formatTime(time) {
    var h = m = s = ms = 0;
    var newTime = '';

    h = Math.floor( time / (60 * 60 * 1000) );
    time = time % (60 * 60 * 1000);
    m = Math.floor( time / (60 * 1000) );
    time = time % (60 * 1000);
    s = Math.floor( time / 1000 );
    ms = time % 1000;

    newTime = pad(h, 2) + ':' + pad(m, 2) + ':' + pad(s, 2) + ':' + pad(ms, 3);
    return newTime;
}

function show() {
    $time = document.getElementById('time');
    update();
}

function update() {
    $time.innerHTML = formatTime(x.time());
}

function start() {
    clocktimer = setInterval("update()", 1);
    x.start();
}

function stop() {
    x.stop();
    clearInterval(clocktimer);
}

function reset() {
    stop();
    x.reset();
    update();
}

Which runs a stopwatch.

My CSP conf has this unsafe-eval directive. It is insecure, so I removed it. And my code won’t work and says in the console log that

    clocktimer = setInterval("update()", 1);

is not allowed to run. How can I make it so that it can be run without the unsafe-eval directive?

I am unable to know what to do because I am really new to JS.

Answer

"update()" is just a string, and can’t be called. You need to pass the function.

// Reference the function (probably better)
clocktimer = setInterval(update, 1)

// Call function with lambda (better in some situations, but not this one)
clocktimer = setInterval(() => update(), 1)