mardi 10 septembre 2019

javascript: How can i access class methods and attributes inside a function in class

I have a class which contain a function, so i want to able to call some of class method inside this function

class Upload {
* uploadFiles(files: FileList | File[]) { 
let file;
for (let i = 0; i < files.length; i++) {
  if (filesAdded === 1) {
      break;
  }
  file = files[i];
   if (this.types.indexOf(file.type) > -1) {
       filesAdded++;
    } else {
        this._showBadExtensionError();
         return false;
    }
  }
        var worker_fn = () =>
        {
            this.send(file); // i want to able to access send() method and file attribute above 
            self.postMessage('upload sucessfully...');
        };
        var blob = new Blob(["onmessage ="+worker_fn.toString()], { type: "text/javascript" });

        var worker = new Worker(window.URL.createObjectURL(blob));

}
send(file: File, url) {
  let formData = new FormData(); 
  formData.append('file', file, file.name);
  const response = await this.apiRequest.POST(url, formData);
  return response.json();
}

}

i want to find away to access class method send and the attribute file inside worker function ?




Aucun commentaire:

Enregistrer un commentaire