setInterval Spotify 应用程序

发布于 2024-12-25 23:34:27 字数 343 浏览 3 评论 0原文

我在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空城之時有危險 2025-01-01 23:34:27

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.

浅暮の光 2025-01-01 23:34:27

这对我来说效果很好:

this.interval = setInterval(function() {
    console.log("tick");
}.bind(this), 100);

This works fine for me:

this.interval = setInterval(function() {
    console.log("tick");
}.bind(this), 100);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文