Created
March 27, 2013 09:53
-
-
Save gurdotan/5253093 to your computer and use it in GitHub Desktop.
jQuery Deferred objects - example
This file contains 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
// Based on http://www.intridea.com/blog/2011/2/8/fun-with-jquery-deferred | |
$.wait = function(time) { | |
var deferred = $.Deferred(function(dfd) { | |
setTimeout(dfd.resolve, time); | |
}); | |
// Can return susbset of Deferred object | |
// without any state mutating functionality: | |
// | |
// return deferred.promise() | |
return deferred; | |
} | |
// Example usage | |
$.wait(5000).then(function() { | |
alert("Hello from the future!"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment