jQuery Deferred – one step closer to desktop apps

Every time I forget why I like jQuery, they keep reminding me. Not too long ago I came across jQuery deferred (even though it was added already in JQuery 1.5) and I immediately liked it. I feel this feature brings the web application development a bit closer to the desktop development. Deferreds simply let you add multiple callback to long lasting operation calls like Ajax requests. Long lasting operations without JQuery Deferred If you haven’t used deferreds, this is probably how you had done long lasting actions like ajax calls. Long lasting operations like ajax require a callback function. In this case the callback is given as a parameter to the caller. This is fine, but there is a way to add a callback separately from the call. Try it This is actually the simplest example of using Deferreds. JQuery ajax methods (get,post,ajax…) return an object which you can add callback methods to it. Why is it better? Simply because it lets you keep the logic of execution and the logic of the result separated. This makes a more readable and maintainable code. So what is a ‘Deferred’? Deferred is an object which lets you add multiple callback methods to Continue reading jQuery Deferred – one step closer to desktop apps