Podczas czytania poniższego testu wydajności zauważyłem, że autor używał $(0)
i $(1)
. Jaki jest tego cel?
http://jsperf.com/scriptjunkie-premature-3
var $a = $(0);
function fn_1() {
var $a = $(this);
if ($a.attr("rel") == "foo") {
$a.addClass("foo");
}
else {
$a.addClass("other");
}
}
function fn_2() {
$a.context = $a[0] = this; // fake the collection object
if ($a.attr("rel") == "foo") {
$a.addClass("foo");
}
else {
$a.addClass("other");
}
}
Niezależnie od tego zachowania, jest ono nieudokumentowane. '$ (0) => []' i '$ (1) => [1]' (i '$ (2) => [2]'), ale nie mam pojęcia, dlaczego:/ – Matchu
Czy przeczytałeś artykuł ten test łączy się z? –
Dzięki @FelixKling, nie zauważyłem, że istnieje link! Najpierw czytałem [to] (https://docs.google.com/present/view?id=0Ac0YlG9vMA2LZHE1MnpycF8yMGZ6ZnZxa2hy&pli=1) =] – Ton