setInterval Spotify 应用程序
我在使用 setInterval/clearInterval 时遇到问题。
我尝试做这样的事情: int = setInterval(someFunction(), 1000);
但它只调用 someFunction()
一次,而不是每秒调用一次?
所以我尝试这样做: int = setInterval("someFunction()", 1000);
它实际上以某种方式工作,因为它给了我这个错误 Uncaught ReferenceError: someFunction is not每秒定义一次?
为什么? d:
I'm having trouble using setInterval/clearInterval.
I've tried to do something like this: int = setInterval(someFunction(), 1000);
but it only call someFunction()
once, instead of once every second?
So I tried to do this: int = setInterval("someFunction()", 1000);
and it actually works in some way, because it gives me this error Uncaught ReferenceError: someFunction is not defined
every second?
Why? D:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
setInterval
接受两个参数:一个函数和一个以毫秒为单位的调用之间的时间。您的第一个示例是错误的,因为它没有给出函数作为参数,它执行该函数并将结果作为第一个参数传递。只需将其更改为
setInterval(someFunction, 1000)
即可。setInterval
takes two arguments: a function, and a time in milliseconds for the time between calls.Your first example is wrong because it doesn't give a function as argument, it executes the function and passes the result as the first argument. Just change it to
setInterval(someFunction, 1000)
and it'll work.这对我来说效果很好:
This works fine for me: