@@ -636,6 +636,7 @@ forEach({
636
636
*/
637
637
JQLite . prototype [ name ] = function ( arg1 , arg2 ) {
638
638
var i , key ;
639
+ var nodeCount = this . length ;
639
640
640
641
// jqLiteHasClass has only two arguments, but is a getter-only fn, so we need to special-case it
641
642
// in a way that survives minification.
@@ -645,7 +646,7 @@ forEach({
645
646
if ( isObject ( arg1 ) ) {
646
647
647
648
// we are a write, but the object properties are the key/values
648
- for ( i = 0 ; i < this . length ; i ++ ) {
649
+ for ( i = 0 ; i < nodeCount ; i ++ ) {
649
650
if ( fn === jqLiteData ) {
650
651
// data() takes the whole object in jQuery
651
652
fn ( this [ i ] , arg1 ) ;
@@ -659,9 +660,10 @@ forEach({
659
660
return this ;
660
661
} else {
661
662
// we are a read, so read the first child.
663
+ // TODO: do we still need this?
662
664
var value = fn . $dv ;
663
665
// Only if we have $dv do we iterate over all, otherwise it is just the first element.
664
- var jj = ( value === undefined ) ? Math . min ( this . length , 1 ) : this . length ;
666
+ var jj = ( value === undefined ) ? Math . min ( nodeCount , 1 ) : nodeCount ;
665
667
for ( var j = 0 ; j < jj ; j ++ ) {
666
668
var nodeValue = fn ( this [ j ] , arg1 , arg2 ) ;
667
669
value = value ? value + nodeValue : nodeValue ;
@@ -670,7 +672,7 @@ forEach({
670
672
}
671
673
} else {
672
674
// we are a write, so apply to all children
673
- for ( i = 0 ; i < this . length ; i ++ ) {
675
+ for ( i = 0 ; i < nodeCount ; i ++ ) {
674
676
fn ( this [ i ] , arg1 , arg2 ) ;
675
677
}
676
678
// return self for chaining
0 commit comments