Skip to main content


Showing posts from February, 2013

JavaScript [Q.JS] Are you stuck in nested callback functions?

If you have seen situation when one asynchronous call result used in another asynchronous call. And you tried to make that code look less scary and more readable then you must go through this library and understand it’s nice tricks and syntax. Just want to give the same example from its site which clearly shows the problem it is trying to solve.   step1(function (value1) { step2(value1, function(value2) { step3(value2, function(value3) { step4(value3, function(value4) { // Do something with value4 }); }); }); });   With QJS library     Q.fcall(step1) .then(step2) .then(step3) .then(step4) .then(function (value4) { // Do something with value4 }, function (error) { // Handle any error from step1 through step4 }) .done();   If you want to see its potential uses then you should see one of the WCF data API  breezejs . To test this library i have created a dummy Ajax function which simulate the Ajax asynchrono