I don't understand why beneath code is not working.
function doSome(){
console.log("Hi");
}
setInterval(doSome(), '1000');
what I expected :
// every second
Hi
Hi
Hi
...
but result
TypeError: Cannot read property 'call' of undefined
at wrapper [as _onTimeout] (timers.js:275:18)
at Timer.listOnTimeout (timers.js:92:15)
Okay, If I change setInterval(doSome(), '1000'); to setInterval(function(){doSome()}, '1000'); The code works finely. But I don't know what is different, and why I have to wrap the function like function(){...} Can you tell me some hints, Thanks...
setInterval(doSome(), '1000');==>setInterval(doSome, 1000);when passing function as reference, use only function name. Remove()ofdoSome, time should not be string().. you are invoking the function. You need to pass a reference, therefore it should besetInterval(doSome, 1000);