Created
December 6, 2011 09:35
-
-
Save dhavaln/1437552 to your computer and use it in GitHub Desktop.
jQuery Differed 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
function showData() { | |
console.log("final value :" +newArray.length); | |
console.log(newArray); | |
} | |
var newArray = []; | |
function method1() { | |
return $.Deferred(function( dfd ){ | |
self.setTimeout(function(){ | |
newArray.push("hello"); | |
dfd.resolve(); | |
}, 3000); | |
}).promise(); | |
} | |
function method2(){ | |
return $.Deferred(function( dfd ){ | |
self.setTimeout(function(){ | |
newArray.push("world"); | |
dfd.resolve(); | |
}, 3000); | |
}).promise(); | |
} | |
console.log("starting method1"); | |
$.when(method1()).then( | |
function(){ | |
console.log("starting method2"); | |
$.when(method2()).then(showData); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment