Hacker News new | ask | show | jobs
by zbanks 5468 days 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();
1 comments

Absolutely - 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.