Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A study in jQuery deferreds, based on Lu4's answer to “jQuery deferreds and promises - .then() vs .done()”.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery deferreds and promises - .then() vs .done()</title>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-git.css">
</head>
<body>
<p>
A study in jQuery deferreds, based on <em>Lu4's</em> <a
href="http://stackoverflow.com/a/15694010/27581">answer to “jQuery
deferreds and promises - .then() vs .done()”</a>.
</p>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="http://code.jquery.com/qunit/qunit-1.12.0.js"></script>
<script src="http://code.jquery.com/jquery-1.11.0.js"></script>
<script type="text/javascript">
asyncTest('then then then', function () {
var promise = $.Deferred().resolve('abc');
promise.then(function (x) {
equal(x, 'abc');
return 123;
}).then(function (x){
equal(x, 123);
}).then(function (x){
equal(x, undefined)
start();
});
});
asyncTest('done done done', function() {
var promise = $.Deferred().resolve('abc');
promise.done(function (x) {
equal(x, 'abc');
return 123;
}).done(function (x) {
equal(x, 'abc');
}).done(function (x) {
equal(x, 'abc');
start();
});
});
asyncTest('done then then done done', function () {
var promise = $.Deferred().resolve('abc');
promise.done(function (x) {
equal(x, 'abc');
return 123;
}).then(function (x) {
equal(x, 'abc');
}).then(function (x) {
equal(x, undefined);
return 456;
}).done(function (x) {
equal(x, 456);
}).done(function (x) {
equal(x, 456);
start();
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.