Skip to content

Instantly share code, notes, and snippets.

Created December 13, 2012 15:38
Show Gist options
  • Select an option

  • Save anonymous/4277230 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/4277230 to your computer and use it in GitHub Desktop.
Difference in fail semantics between jQuery promises and WinJS promises
// jQuery - failures persist along the chain
$.Deferred(function(d) { d.reject() })
.then(function() { console.log("Success handler 1") }, function() { console.log("Fail handler 1") })
.then(function() { console.log("Success handler 2") }, function() { console.log("Fail handler 2") });
// Output:
// Fail handler 1
// Fail handler 2
// ------------------------------------------------------------------------------------------------------
// WinJS - failures are swallowed by the first handler and then ignored
new WinJS.Promise(function(complete, err) { err() })
.then(function() { console.log("Success handler 1") }, function() { console.log("Fail handler 1") })
.then(function() { console.log("Success handler 2") }, function() { console.log("Fail handler 2") })
// Output:
// Fail handler 1
// Success handler 2
@mbest
Copy link
Copy Markdown

mbest commented Dec 15, 2012

The difference is actually the meaning of then. jQuery's then is weird. Use pipe instead; it's the same as WinJS's then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment