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:
http://stephenwalther.com/archive/2012/02/22/metro-promises.aspx
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: