Javascript function in setInterval

后端 未结 3 1507
悲&欢浪女
悲&欢浪女 2020-12-22 04:07

I have the following code:

var foo=5;
var los= function (){
    alert(foo);};
setInterval(los, 1000);

which works correctly.

If I

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-22 04:27

    Because you're executing los() and then the result of that (single) execution is passed into the setInterval function.

    setInterval requires a function passed in, not undefined, which is what los returns. However, it doesn't complain - it just doesn't do anything.

提交回复
热议问题