-3

I'm new to JavaScript and I'm not sure how to convert these two arrow functions into regular functions. If someone could convert them and give me an explanation that would be great!

function getBase64(file) {
    try {
            return new Promise(resolve => {
    //var file = new File([filename], filepath);
    var reader = new FileReader();
    // Read file content on file loaded event
    reader.onload = function(event) {
            $window.setTimeout(()=>{
        resolve(reader.result.replace(/^data:.+;base64,/, ''));
            },250);
    };      
    reader.readAsDataURL(file); 
            });
    }
        catch (e)
            {
                console.log ("error "+ e);
            }
    }
blionzion
  • 49
  • 3

2 Answers2

1

Community members had already provided you the suggestions to convert the arrow functions into regular functions.

So I hope now you have an idea about how to do it manually.

If you have a large code that uses the hundreds of arrow functions then I suggest trying to use the Babel.js to transpile your ES6 code to ES5 code that will work with the IE browser.

It will be the easiest approach to convert the arrow functions into regular functions for a large code.

Example of transpiled code using Babel:

"use strict";

function getBase64(file) {
  try {
    return new Promise(function (resolve) {
      //var file = new File([filename], filepath);
      var reader = new FileReader(); // Read file content on file loaded event

      reader.onload = function (event) {
        $window.setTimeout(function () {
          resolve(reader.result.replace(/^data:.+;base64,/, ''));
        }, 250);
      };

      reader.readAsDataURL(file);
    });
  } catch (e) {
    console.log("error " + e);
  }
}
Deepak-MSFT
  • 10,379
  • 1
  • 12
  • 19
0

(x,y,z) => w

becomes...

function(x,y,z){ return w; }

() => { y; }

becomes

function() { y; }

vicatcu
  • 5,407
  • 7
  • 41
  • 65