it's not backwards. first function is on top, last at the bottom, functions, which may appear multiple times in the callback chain are at the top most position by convention. i use the function declaration statement for this, because they get hoisted and the definition order is irrelevant then. There is no problem with named functions, they are good for stack-traces anyway. here just a snippet:
function rebuild(){ checkErr.apply(null,arguments) vLog('rebuild dependencies...') exec("npm rebuild", dbJSON) } function dbJSON(){ checkErr.apply(null,arguments) vLog('database.json...') exec("cp -f config/database.shared.json config/database.json", createLogFolder) } function createLogFolder(){ checkErr.apply(null,arguments) vLog('create log folder...') if (fs.existsSync('./log')) prepareDistribution() else exec("mkdir log && touch log/dummy_file", prepareDistribution) } function prepareDistribution() { checkErr.apply(null,arguments) vLog('prepare distribution...') exec('git add . -Af && git commit -m "deployment script done preparation"', deploy) } its a part of a script that just runs on bare node. it's an approach you always can be used, in every node environment. it just use functions with well defined scope, they can be easily reused. the disadvantage of this approach is that you need to use bind or shared variables in outer scope instead of clojure scope. bind is much slower in v8, and shared variables may be evil. Am Montag, 12. November 2012 23:48:33 UTC+1 schrieb Andy: > > One of them problems even with this approach is that you write and read > code backwards. It executes bottom to top because you have to define named > callback functions first. I find it much more natural with promises because > not only is your code organized, but it reads top to bottom and is MUCH > easier to trace flow. > > On Monday, November 12, 2012 1:39:37 AM UTC-8, greelgorke wrote: >> >> >> function execCB(err, stdout,stderr){ >> require('assert').ok(~stdout.indexOf( this )) >> } >> >> function lolAssert(){ >> var forClojure = 'lol' >> require('child_process').exec('echo lol', execCB.bind(forClojure)) >> } >> > -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to nodejs@googlegroups.com To unsubscribe from this group, send email to nodejs+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en