class myFetch{ constructor(count){ this.sumCount = count; this.resCount = 0; } request(method, api){ if(method === 'POST'){ this.myPost(api) } if(method === 'GET'){ } } myPost(url){ this.myFecth(url) } myFecth(url){ if(this.resCount < this.sumCount){ fetch(url).then(res=>{ if(res.errcode === 200){ console.log('success') } }).catch(err=>{ this.resCount++; if(this.resCount < this.sumCount){ this.myFecth(url) } }) } } }