Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why jsHint says "'setInterval' is not defined"

When I check my *.js with jshint, it's show an error on this part:

function updateStatistic(interval) {
    return setInterval(function () {
        exports.getStatistics();
    }, interval);
}

The message is: 'setInterval' is not defined. But why?

like image 528
Sergei Panfilov Avatar asked Aug 07 '14 07:08

Sergei Panfilov


People also ask

What can I use instead of setInterval?

Nested setTimeout calls are a more flexible alternative to setInterval , allowing us to set the time between executions more precisely. Zero delay scheduling with setTimeout(func, 0) (the same as setTimeout(func) ) is used to schedule the call “as soon as possible, but after the current script is complete”.

How does the setInterval () function work in?

setInterval() The setInterval() method, offered on the Window and Worker interfaces, repeatedly calls a function or executes a code snippet, with a fixed time delay between each call. This method returns an interval ID which uniquely identifies the interval, so you can remove it later by calling clearInterval() .

What does setInterval do in JavaScript?

JavaScript setInterval() method. The setInterval() method in JavaScript is used to repeat a specified function at every given time-interval. It evaluates an expression or calls a function at given intervals. This method continues the calling of function until the window is closed or the clearInterval() method is called ...

How do you clear setInterval?

The clearInterval() function in javascript clears the interval which has been set by setInterval() function before that. setInterval() function takes two parameters. First a function to be executed and second after how much time (in ms). setInterval() executes the passed function for the given time interval.


1 Answers

Alternatively, you could just have JSHint assume a browser:

/*jshint browser: true */

(Reference)

like image 121
tckmn Avatar answered Oct 06 '22 09:10

tckmn