开发者

Indenting/breaking jquery chains for readability [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 11 years ago.

I'm curious as to how other people indent/break long jQuery chains, as I can never decide what is more readable (particularly when using .end() to "close" a block of methods e.g.

$(this).not(":has(.pointer)").append(pointerHtml)
                .end()
            .closest("li").toggleClass("selected")
            .siblings().removeClass("selected")
            .andSelf().removeClass("pre-selected")
     开发者_开发技巧           .end().end()
            .filter(".selected").prev().addClass("pre-selected");

How would YOU format this?


$(this).not(":has(.pointer)")
           .append(pointerHtml)
           .end()
           .closest("li")
           .toggleClass("selected")
           .siblings()
           .removeClass("selected")
           .andSelf()
           .removeClass("pre-selected")
           .end()
           .end()
           .filter(".selected")
           .prev()
           .addClass("pre-selected");
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜