> BTW, the return in case B is ignored and not needed. What about short circuiting? The example didn't illustrate short-circuiting but it's somewhat common and probably the OP's inspiration.
function (opts, cb) { thing(opts, function (err, data) { if (err) { cb(err); return; } var result = transform(data); cb(null, result); }); }); In this case, we use return to stop callback execution, and for async use the actual return value doesn't matter because it can't get assigned to anything so combining the lines into `return cb(err)`makes for a reasonable shorthand. Other than that, they're roughly equivalent. --Josh On Tue, Apr 10, 2012 at 4:26 PM, Mark Hahn <m...@hahnca.com> wrote: > BTW, the return in case B is ignored and not needed. > > > On Tue, Apr 10, 2012 at 4:24 PM, Mark Hahn <m...@hahnca.com> wrote: >> >> The only difference is that the return value of foo takes on the >> callback's return value instead of null. There is no other difference at >> all. >> >> >> On Tue, Apr 10, 2012 at 4:17 PM, Ken <ken.woodr...@gmail.com> wrote: >>> >>> Assuming that the callback doesn't return a value, does v8 behave any >>> differently when invoking callbacks in one of these forms vs. the other? I >>> find the first approach to be a convenient shorthand in many cases, but am >>> wondering (after observing some unexpected timings when profiling async >>> methods) if it leads to v8 doing something odd with the stack. >>> >>> Approach A, return the invoked callback: >>> >>> function foo(a, callback) { >>> var bar = ...; >>> return callback(bar); >>> } >>> >>> foo("derp", function(b) { ...; return; }); >>> >>> Approach B, invoke callback, then return: >>> >>> function foo(a, callback) { >>> var bar = ...; >>> callback(bar); >>> return; >>> } >>> >>> foo("derp", function(b) { ...; return; }); >>> >>> -- >>> 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 >> >> > > -- > 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 -- Joshua Holbrook Engineer Nodejitsu Inc. j...@nodejitsu.com -- 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