Created
May 10, 2014 19:13
-
-
Save iladarsda/a250de6605e691a6fda8 to your computer and use it in GitHub Desktop.
jQuery/javascript running functions synchronously
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 fun1() { | |
setTimeout(function() { | |
console.log("fun1 after 5 s.."); | |
}, 5 * 1000); | |
return this; | |
}; | |
function fun2() { | |
setTimeout(function() { | |
console.log("fun2 after another 15 s.."); | |
}, 15 * 1000); | |
return this; | |
}; | |
window.fun1().fun2(); |
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
$(document).ready(function() { | |
$.fn.fun1 = function() { | |
setTimeout(function() { | |
console.log("fun1 after 5 s.."); | |
}, 5 * 1000); | |
return $(this); | |
}; | |
$.fn.fun2 = function() { | |
setTimeout(function() { | |
console.log("fun2 after another 15 s.."); | |
}, 15 * 1000); | |
return $(this); | |
}; | |
$(document).fun1().fun2(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment