export const timer = (time,fun) => {
let timeId = setTimeout (() => {
fun()
},time)
}
定时器在js里面封装如何抛出返回结果
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
_念_ 2022-02-28 17:31关注export const timer = (time,fun) => { return new Promise((resolve) => { let timeId = setTimeout(() => { resolve(fun()); clearTimeout(timeId); }, time); }); } timer(1000, () => "123").then(res => console.log(res));本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报