WinJS Promises

I’m working on an app for Windows 8, and I decided that I would try doing it in HTML5 and Javascript (WinJS), thinking that I’d have an easier time with arranging HTML than with arranging XAML.

I’m pretty sure that isn’t going to be the case as it seems like it’s hard to make my app not look like a formatted webpage (no duh) instead of a native app.  But anyway, the one thing that is cool to see is that MS is making sure that lots of stuff in WinJS uses promises.

A promise is a way to deal with callbacks, but usually in a nicer and more fluent manner.  Rather than messing around with timeouts and callbacks, you can write code like something.execute().then(finish()).done(cleanup());

WinJS has it’s own Promise object.  There is a very nice write up here:

The best example is this one showing the full life cycle of a WinJS promise:


When working in regular javascript (instead of WinJS), you can make use of a number of different promise libraries:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s