Skip to content

Instantly share code, notes, and snippets.

@iladarsda
Created May 10, 2014 19:13
Show Gist options
  • Save iladarsda/a250de6605e691a6fda8 to your computer and use it in GitHub Desktop.
Save iladarsda/a250de6605e691a6fda8 to your computer and use it in GitHub Desktop.
jQuery/javascript running functions synchronously
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();
$(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