Sunday, January 15, 2012

Quick Left | Leveraging Deferreds in Backbone.js

Quick Left | Leveraging Deferreds in Backbone.js: ""[Deferred objects are] chainable utility object[s] that can register multiple callbacks into callback queues, invoke callback queues, and relay the success or failure state of any synchronous or asynchronous function."
Basically, if you have access to a deferred object, you can reliably bind callback functions to the state of a function now and forever, regardless of how or when that function is "resolved."
Now whats really cool is that jQuery AJAX functions return a Deferred object. This is what lets you chain callbacks directly off of AJAX methods, but it's even better when you can leverage that returned value from a completely different scope. This becomes a really important behavior in a Backbone app, but only if you know how to take advantage of it."

'via Blog this'