Nested callbacks get really cumbersome after a while. Let's see some alternatives for a better Future of JS.
I Promise it will make your js code nicer.
{! // do something with the response! });! ! req.fail(function() {! // do something if the request failed! });! ! var lis = $(“li”);! req.done(function(response) {! // do more stuff with response and lis! })!
of: func(args…,callback(err,arrgs…))! ! • Some libraries are handling the implementations of Promises • They got into an agreement called Promises/ A+ – http://promises-aplus.github.io/promises-spec/
show some code use the Q library https://github.com/kriskowal/q • Q.nfbind :: (err -> result -> ()) -> Promise result! • Q.all :: [Promise] -> Promise [Promise]! • Q.spread :: [Promise] -> Promise args… -> Promise! • This is not the exactly type signature, nor Haskell syntax, it is just similar!
api’s that uses the community style guide to maximize integration – Expose func(args…, callback(err, arrgs…))! • Use Promises internally to make future data interaction and flow more explicit • Use callbacks when it makes sense (ie: click events…) • Everything in excess is bad • Try more functional approaches (: