News for hackers. Stuff that matters.
Re:Managing Node.js Callback Hell with Promises, Generators ... by porphyry3 on Tuesday February 04, 2014 @03:34PM (#7180074)
There is another nice feature of ES6 that helps a lot with callbacks and promises: proxies. Check out this article I wrote on Flippin Awesome (http://flippinawesome.org/2013/11/18/taming-asynchronous-jav...). The following is some sample code to show how code can be simplified with ES6 proxies, making async functions chainable (example in coffeescript):

    getUser = (user) ->
        _("https://npmjs.org/~#{user}")
          .get()
          .extractLinks()
          .filter( -> /package/.test(arguments[0]) )
          .map( -> "https://npmjs.org#{arguments[0]}" )
          .log()
    
    getUser("foo")
where `get` is THE jQuery get for Ajax requests returning a promise and is chained with the rest of the functions in a pipeline fashion. I've found that these techniques can work very well for form validation, as [you can check here](http://www.vittoriozaccaria.net/chained/demo.html) — Firefox required.

Edit: I wrote in markdown but it seems that only verbatim is supported. Edit2: some clarification

There are no comments on this comment yet.