Durante la lettura del seguente test delle prestazioni, ho notato che l'autore utilizzava $(0)
e $(1)
. Qual è lo scopo di questo?
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");
}
}
Qualunque sia questo comportamento, non è documentato. '$ (0) => []' e '$ (1) => [1]' (e '$ (2) => [2]'), ma non ho idea del perché:/ – Matchu
Hai letto il articolo a cui questo test si collega? –
Grazie a @FelixKling, non ho notato che c'è un link! Prima stavo leggendo [questo] (https://docs.google.com/present/view?id=0Ac0YlG9vMA2LZHE1MnpycF8yMGZ6ZnZxa2hy&pli=1) =] – Ton