How to self-execute the old error report by object-oriented

Thank you for your help. Finally, the implementation code is released, and the @ sheep method is also fine, but I have a problem on the mobile end, and I am still looking into the cause

.
var wxSdk = {
uploadImage (localIds,call){
    let that =this
    if (!wxSdk.ua.isWeiXin()) {
      //Toast("");
      return false;
    }else {
      return new Promise(function(resolve, reject) {
        if(localIds.length == 0){
          //
          resolve(serverIds);
          call && call(serverIds);
        }else{
          wx.uploadImage({
            localId: localId, // IDchooseImage
            isShowProgressTips: 1, // 1
            success: function (res) {
              serverIds.push(res.serverId);//// ID
              that.uploadImage(localIds,call);
            }
          });
        }
      });
    }
  }
}
May.22,2021

if your code is to express the localId of all the pictures that need to be uploaded is placed in the array localIds, and you upload one by one, know that the array is empty, then stop executing this logic, the problem occurs in the following areas:
1. If you use Promise, you don't have to use callback
2. The length of your localIds array is not reduced, so it won't go into resolve.
3. It is wrong to make a recursive call with Promise.
I wrote one to simulate your requirements, because I don't know your localIds,serverIds, so I simulated two.


 var array=[];
    function output(j) {
        return new Promise( function(resolve, reject) {
            setTimeout(function () {
                console.log('',j)
                return resolve(j);
            },1000 * j);
        }).then(function (res) {
            return Promise.resolve(res)
        });
    }

    for (var i=0;i<5;iPP){
        array.push(output(i));
    }
    Promise.all(array).then(function (res) {
        console.log('res',res);
    });
Menu