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);
});
});
};