0

Below is a sample code, which I found from a blog. I noticed that the blogger uses both the standard function and arrow function. Can someone explain why which type of function is suitable for which case, using the example below?

const readFileAsArray = function(file, cb = () => {}) {
  return new Promise((resolve, reject) => {
    fs.readFile(file, function(err, data) {
      if (err) {
        reject(err);
        return cb(err);
      }
      const lines = data.toString().trim().split('\n');
      resolve(lines);
      cb(null, lines);
    });
  });
};
Sihoon Kim
  • 815
  • 8
  • 18
  • 5
    Possible duplicate of [When should I use Arrow functions in ECMAScript 6?](https://stackoverflow.com/questions/22939130/when-should-i-use-arrow-functions-in-ecmascript-6) – Andreas Nov 24 '18 at 12:19
  • this in arrow functions is lexically scoped, that's their outstanding feature. But you need a dynamically bound this, and that's what functions are good for. – programoholic Nov 24 '18 at 12:21
  • Go through : https://stackoverflow.com/questions/34361379/arrow-function-vs-function-declaration-expressions-are-they-equivalent-exch – programoholic Nov 24 '18 at 12:21

0 Answers0