JavaScript - SetInterval doesn't function properly

前端 未结 4 1747
忘掉有多难
忘掉有多难 2021-01-13 22:40

I got this piece of script (runned locally):



        
4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-13 23:05

    You need to remove the () after uploadnew within the setInterval call:

    setInterval (uploadnew, 1000*60*5);
    

    In JavaScript, functions are first-class objects which can be passed to other functions. In this example, you want to pass the function itself to setInterval, not call it first and then pass its return value.

    Using setInterval ("uploadnew()", 1000*60*5); is not recommended because it is a "hidden" form of eval. Eval is evil and you shouldn't use it if you don't have to.

提交回复
热议问题