ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
```js // 每隔一段时间time执行一次定时器 // setTimeout:创建一个定时器对象 // 在setTimeout清除之前创建一个新的 let timer = null function timeInterval(func, wait) { let timer = null function interval() { // 执行 func 函数 // 并且重新设置一个定时器 func() timer = setTimeout(interval, t) } interval() return { cancel: () => { clearTimeout(timer) } } } ```