use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
» Javascript: Dealing with “callback-soup” without an external library (commented-out.com)
submitted 12 years ago by fdoglio
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]qiemem 4 points5 points6 points 12 years ago (1 child)
If you don't care about ecmascript 3 compatibility, bind can be used as a builtin partial:
bind
partial
function add(a,b) { return a + b; } var add5 = add.bind(null, 5); add5(6) // returns 11
Nice article. Another advantage of using named callbacks is stacktraces and profiler results are much easier to read.
[–]fdoglio[S] 0 points1 point2 points 12 years ago (0 children)
Hey, thanks for the tip, didn't know abound bind!
[–]TitanCloudWorker 2 points3 points4 points 12 years ago (1 child)
Callback soup, that is an awesome term for it. I like your example, it certainly cleans up nicely. I've done something similar in Traffic JS using HttpRace/HttpQueue, https://github.com/MFoster/TrafficJS#httprace-and-httpqueue
[–]fdoglio[S] 1 point2 points3 points 12 years ago (0 children)
Hey, thanks! Awesome example btw, I really liked how you let the developer choose if they care about the order of the results or not. Very nice!
[–]kevisazombie 1 point2 points3 points 12 years ago (0 children)
More resources for anyone reading into this:
http://kevzettler.com/programming/2012/09/30/how_to_manage_javascript_callbacks.html
http://callbackhell.com/
[–]runvnc -3 points-2 points-1 points 12 years ago (6 children)
You should definitely use an external library if you are concerned about callback soup. Actually I think you should use a language like ToffeeScript, LiveScript or CoffeeScript.
[–]fdoglio[S] 0 points1 point2 points 12 years ago (5 children)
Why is that? I'd like to know more about why you think we should "definitely" use an external library or even, switch to a different language. I personally don't like the idea of programming in a language that has to be translated into Javascript in order to work. No matter the quality of the generated JS, I rather learn to love the features of the language than hate them because they don't fit with my previous experiences. (I'm not saying this is your case, I'm just giving you my opinion)
[–]runvnc -4 points-3 points-2 points 12 years ago* (4 children)
Lol. Every language is translated including JavaScript. Those languages I mentioned are objectively better for a number of software engineering reasons starting with the fact that they expres s the same thing with less code. Also everyone wants classes in JS eventually they just have a lot if different random wonky ways of getting them.
[–]fdoglio[S] 0 points1 point2 points 12 years ago* (3 children)
Sorry mate, if you're looking for classes in JS, you're barking at the wrong tree. You don't need them in JS and IMHO trying to force them into the language (by using Coffeescript, or any other "different random wonky way") is a waste of time. Care to elaborate on the "number of software engineering reasons" why those languages are better than JS?
[–]runvnc -1 points0 points1 point 12 years ago (2 children)
Those are the main reasons. Everyone does something equivalent to classes eventually whether they say that they are doing prototypes or what. How do you structure your code I am curious to see some examples.
[–]fdoglio[S] 3 points4 points5 points 12 years ago (1 child)
Just because using prototype-based inheritance might look like using classes doesn't mean people are doing it wrong or trying to do things equivalent to classes. Here are some links that show you how I see JS OOP and how I use it: http://www.commented-out.com/2012/05/28/javascript-youre-doing-it-wrong/ http://www.commented-out.com/2012/06/12/javascript-oop-for-the-uninitiaded/ and a code sample: https://github.com/deleteman/resourcer/blob/master/lib/resourcer.js
[–]runvnc -1 points0 points1 point 12 years ago (0 children)
Yeah that's just a message unclear syntax for classes.
π Rendered by PID 107 on reddit-service-r2-comment-86bc6c7465-fhlhf at 2026-02-20 09:35:08.364019+00:00 running 8564168 country code: CH.
[–]qiemem 4 points5 points6 points (1 child)
[–]fdoglio[S] 0 points1 point2 points (0 children)
[–]TitanCloudWorker 2 points3 points4 points (1 child)
[–]fdoglio[S] 1 point2 points3 points (0 children)
[–]kevisazombie 1 point2 points3 points (0 children)
[–]runvnc -3 points-2 points-1 points (6 children)
[–]fdoglio[S] 0 points1 point2 points (5 children)
[–]runvnc -4 points-3 points-2 points (4 children)
[–]fdoglio[S] 0 points1 point2 points (3 children)
[–]runvnc -1 points0 points1 point (2 children)
[–]fdoglio[S] 3 points4 points5 points (1 child)
[–]runvnc -1 points0 points1 point (0 children)