Domanda

Are the following 2 pretty much the same, or one is better and why?

A)

$myLists.find(".panel").hide().end()
    .find(".tabs a.active").removeClass("active").end()
    .find($this.attr("href")).fadeIn(250);

B)

$myLists.find(".panel").hide();
$myLists.find(".tabs a.active").removeClass("active");
$myLists.find($this.attr("href")).fadeIn(250);
È stato utile?

Soluzione

The difference in performance, if there is one, is outstandingly minuscule. It is not worth bothering about.

The only other difference there could be would be in ease of reading and writing the code. That question is really up to you. I find your chained code quite confusing. If I were to do it that way, I would do something like this:

$myLists
    .find(".panel")
        .hide()
        .end()
    .find(".tabs a.active")
        .removeClass("active")
        .end()
    .find($this.attr("href"))
        .fadeIn(250);

Indenting the code this way allows you to see precisely what elements you're working on at any given time. As I say, though, this is very much a matter of preference or your house coding style.

Altri suggerimenti

I doubt there is any significant difference in the performance between the two. I would go for option B simply because I find it more 'readable' (even though truth be told in this particular case A is just as readable).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top