I am reading a book on node design patterns, this is some code from page 99 here:
function download(url, filename, callback) {
console.log(`Downloading ${url}`);
let body;
async.series([
callback => { //[1]
request(url, (err, response, resBody) => {
if(err) {
return callback(err);
}
body = resBody;
callback();
});
},
mkdirp.bind(null, path.dirname(filename)), //[2]
callback => { //[3]
fs.writeFile(filename, body, callback);
}
], err => { //[4]
if(err) {
return callback(err);
}
console.log(`Downloaded and saved: ${url}`);
callback(null, body);
});
}
I'm not following what happens at //[2]
. The book says you are partially applying the function with bind. From my understanding from mdn here, when you use bind
you do not invoke the function.
How does this code work if you don't call mkdirp()
later on?
Aucun commentaire:
Enregistrer un commentaire