开发者

Solving chained callbacks in Jquery

开发者 https://www.devze.com 2023-03-29 10:00 出处:网络
I try to understand whats happening within this code: (This is said to be a very effective way for solving chained callbacks)

I try to understand whats happening within this code: (This is said to be a very effective way for solving chained callbacks)

(function hidenext(jq){
    jq.eq(0).fadeOut开发者_如何学Go("fast", function(){
        (jq=jq.slice(1)).length && hidenext(jq);
    });

})($('div#bodyContent a'))

Would really appreciate some help!

Thanks, Freddie from Sweden


Hallå Freddie from Sweden

Let me see if I can re-write it for you:

function hidenext(jq){
    jq.eq(0).fadeOut("fast", function(){
        jq=jq.slice(1);
        if (jq.length !== 0) {
           hidenext(jq);
        }
   });

};
hidenext($('div#bodyContent a'));

In words: given a list of elements, fade the first one out and when that fade completes, take the list that consists of everything but the first element and, if that list is non-empty, tail-recurse.

Hope this helps.

Michael from California

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号