//使下面调用代码能正常工作
const repeatFunc = repeat(console.log, 4, 3000)
repeatFunc("helloworld")//会输出四次helloworld,每次间隔3s
答案:
function repeat (func, times, wait) {
return async function(...arg){
for(let i=0;i<times;i++){
await new Promise(function(res,rej){
setTimeout(() => {
func.apply(this,arg)
res()
}, wait);
})
}
}
}