views:

260

answers:

1

This is my code...

var _before = function () {
    for (var i = 0; i <= 10000; i++) {
     console.log(i);
    }
};

var _appear = function () {
    console.log('i am in the middle of it');
};

var _after = function () {
    console.log('all done!');
};

jQuery.fn.doSomething = function() {
    this.click(function() {
     _before();
     _appear();
     _after();
    });
};

$('#someButton').doSomething();

I want to build a queue inside the doSomething function to allow _before() to complete before firing _appear() and _appear() to complete before firing _after().

I cannot change the structure of the code.

Thanks

+1  A: 

Can't see why it wouldn't be synchronous, as there's nothing to suggest its asynchronous.

Have you tried putting the three function calls in a function itself:

jQuery.fn.doSomething = function() {
    this.click(function() {
        doAll();
    });
};

jQuery.fn.doAll = function() {
    _before();
    _appear();
    _after();
};

Or can you not do this because you can't change the structure?

James Wiseman