निम्नलिखित प्रदर्शन परीक्षण पढ़ने के दौरान, मैंने देखा कि लेखक $(0)
और $(1)
का उपयोग करता था। इसका उद्देश्य क्या है?
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");
}
}
जो भी यह व्यवहार है, यह अनियंत्रित है। '$ (0) => []' और '$ (1) => [1]' (और '$ (2) => [2]'), लेकिन मुझे नहीं पता कि क्यों:/ – Matchu
क्या आपने पढ़ा है इस परीक्षण के लिए आलेख लिंक? –
धन्यवाद @ फ़ेलिक्सक्लिंग, मैंने नहीं देखा कि एक लिंक है! मैं सबसे पहले [यह] पढ़ रहा था (https://docs.google.com/present/view?id=0Ac0YlG9vMA2LZHE1MnpycF8yMGZ6ZnZxa2hy&pli=1) =] – Ton