News for hackers. Stuff that matters.
Re:Avoiding Nested Callbacks in JavaScript by zbanks on Thursday June 30, 2011 @01:57PM (#2715051)
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();
Re:Avoiding Nested Callbacks in JavaScript by panthomakos on Thursday June 30, 2011 @01:59PM (#2715059)
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.