1

这是我的代码...

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();

我想在 doSomething 函数中构建一个队列,以允许 _before() 在触发 _appear() 之前完成,并且 _appear() 在触发 _after() 之前完成。

我无法更改代码的结构。

谢谢

4

1 回答 1

2

不明白为什么它不会是同步的,因为没有任何迹象表明它是异步的。

您是否尝试过将三个函数调用放在一个函数本身中:

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

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

还是因为不能改变结构而不能这样做?

于 2009-08-21T10:48:02.543 回答