Windows 8 Promise Object and JavaScript

One of the best features that I’ve found so far (and I have many more yet to find) are promises.  When building Metro-style apps using JavaScript, the framework utilizes asynchronous requests through xhr.   Within that paradigm, there’s a promise object which essentially says that there will be data there sometime in the future (thus the async request).  The promise object has a method called then, which accepts three arguments, a success function, error function, and a progress function.  This makes the promise object, or the then method, tailored to what we do everyday with AJAX requests:  Send a request, give progress and do something with the results (error or success).

Pseudocode:

WinJS.xhr(“http://example.com/webservice”).then(successFunction, errorFunction, progressFunction);