3 ms·
It's still nesting callbacks, just not inline. Also, for the second example, this might be a cleaner solution: var fs = require('fs'); function write
by zbanks 15y ago
It's still nesting callbacks, just not inline.
Also, for the second example, this might be a cleaner solution:
var fs = require('fs');
function writeFile(filename){
return function(err){
if (err) throw err;
console.log('Wrote ' + filename);
}
}
function writeHello(){
return fs.writeFile('./hello.txt', 'Hello!', writeFile("hello.txt"));
}
function writeWorld(){
return fs.writeFile('./world.txt', 'World!', writeFile("world.txt"));
}
writeHello();
writeWorld();
- panthomakos 15y agoAbsolutely - the code can be re-factored - but your example doesn't demonstrate that you can used named functions/callbacks within closures to further organize code.