先上代码为敬
function TimeCD(times,delay){
//初始化参数
this._init = ()=>{
clearTimeout(this.timer)
this.times = times
this.timer = null
this.init = null
}
this._init()
// 开始倒计时
TimeCD.prototype.start = (operation)=>{
if(!this.init){
this.init = true
eval(operation)
}
return new Promise((resolve,reject)=>{
try {
if(this.times>0){
--this.times