Created
December 13, 2012 15:38
-
-
Save anonymous/4277230 to your computer and use it in GitHub Desktop.
Difference in fail semantics between jQuery promises and WinJS promises
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The difference is actually the meaning of
then. jQuery'sthenis weird. Usepipeinstead; it's the same as WinJS'sthen.