Created
September 9, 2013 18:48
-
-
Save catdad/6499834 to your computer and use it in GitHub Desktop.
jQuery deferred sample
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
//make sure you have jQuery :) | |
//<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> | |
(function(jQuery){ | |
console.log("adding stuff to jQuery"); | |
jQuery.fn.myExtension = function(){ | |
console.log("I'm asynchronous"); | |
var defer = $.Deferred(); | |
setTimeout(function(){ | |
console.log("told you I was asynchronous"); | |
defer.resolve(); | |
}, 1000); | |
return defer.promise(); | |
}; | |
})(jQuery); | |
window.a = $().myExtension().done(function(){ console.log("now it's done"); }); | |
console.log("doing other things... myExtension is done, right?"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment