@@ -652,6 +652,7 @@ forEach({
652
652
*/
653
653
JQLite . prototype [ name ] = function ( arg1 , arg2 ) {
654
654
var i , key ;
655
+ var nodeCount = this . length ;
655
656
656
657
// jqLiteHasClass has only two arguments, but is a getter-only fn, so we need to special-case it
657
658
// in a way that survives minification.
@@ -661,7 +662,7 @@ forEach({
661
662
if ( isObject ( arg1 ) ) {
662
663
663
664
// we are a write, but the object properties are the key/values
664
- for ( i = 0 ; i < this . length ; i ++ ) {
665
+ for ( i = 0 ; i < nodeCount ; i ++ ) {
665
666
if ( fn === jqLiteData ) {
666
667
// data() takes the whole object in jQuery
667
668
fn ( this [ i ] , arg1 ) ;
@@ -675,9 +676,10 @@ forEach({
675
676
return this ;
676
677
} else {
677
678
// we are a read, so read the first child.
679
+ // TODO: do we still need this?
678
680
var value = fn . $dv ;
679
681
// Only if we have $dv do we iterate over all, otherwise it is just the first element.
680
- var jj = ( value === undefined ) ? Math . min ( this . length , 1 ) : this . length ;
682
+ var jj = ( value === undefined ) ? Math . min ( nodeCount , 1 ) : nodeCount ;
681
683
for ( var j = 0 ; j < jj ; j ++ ) {
682
684
var nodeValue = fn ( this [ j ] , arg1 , arg2 ) ;
683
685
value = value ? value + nodeValue : nodeValue ;
@@ -686,7 +688,7 @@ forEach({
686
688
}
687
689
} else {
688
690
// we are a write, so apply to all children
689
- for ( i = 0 ; i < this . length ; i ++ ) {
691
+ for ( i = 0 ; i < nodeCount ; i ++ ) {
690
692
fn ( this [ i ] , arg1 , arg2 ) ;
691
693
}
692
694
// return self for chaining
0 commit comments