ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
``` const repeatFunc = repeat(console.log, 4, 3000); repeatFunc("helloworld"); // 每3秒打印一个helloworld,总计执行4次 function repeat(fn, count, timeout) { return function () { return new Promise((resolve, reject) \=> { let num = 0 let timer timer = setInterval(() => { num++ if (num >= count) { reject() clearInterval(timer) } resolve(fn(arguments[0])) }, timeout); }) } } ```