Unable to access variable outside of function when invoked as setInterval callback

In below code, I defined a function func1.
When func1 is called normally, it works fine.
But, When it is passed into setInterval as a callback, it can’t access variable v1 outside.

In nodejs, both of calling work same.
Is this a bug? Or Is there my mistake?

    (function() {
        let v1 = 0;
        const func1 = function () {

        // working when called normally

        // not working as a callback.
        // unable to access  v1.
        setInterval(func1, 1000, 'test'); 

Error message:

Hello, there is an issue with accessing outer functions.

1 Like

some issue, any solutions?

Could you please try using appsmith store for a temporary workaround like mentioned in the issue comment here.
Hope this helps in unblocking you for now. @poplee @srrrrrr27

1 Like

Thanks. Already i decided to not use setInterval. I will try when i need to use setInterval!!!