I'm trying to understand why function lazy_2
doesn't run this way:
function lazy_1 (callback) {
alert('lazy_1');
}
function lazy_2 () {
alert('lazy_2');
}
lazy_1(lazy_2);
? (Via Execute jquery function after another function completes.)
jQuery method works well:
function lazy_1 (callback) {
alert('lazy_1');
}
function lazy_2 () {
alert('lazy_2');
}
$.when( lazy_1() ).done(function() {
lazy_2();
});
Because lazy_1()
doesn't call it's callback - in fact nobody does. It needs to look like this for the callback to get called:
function lazy_1 (callback) {
alert('lazy_1');
callback();
}
function lazy_2 () {
alert('lazy_2');
}
lazy_1(lazy_2);
Your second code block above is equivalent to:
lazy1();
lazy2();
because you're just asking jQuery $.when()
to run one function and then another with no promises involved (all synchronous code).
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments