Skip to content

Instantly share code, notes, and snippets.

@catdad
Created September 9, 2013 18:48
Show Gist options
  • Save catdad/6499834 to your computer and use it in GitHub Desktop.
Save catdad/6499834 to your computer and use it in GitHub Desktop.
jQuery deferred sample
//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