@@ -636,6 +636,7 @@ forEach({
636636   */ 
637637  JQLite . prototype [ name ]  =  function ( arg1 ,  arg2 )  { 
638638    var  i ,  key ; 
639+     var  nodeCount  =  this . length ; 
639640
640641    // jqLiteHasClass has only two arguments, but is a getter-only fn, so we need to special-case it 
641642    // in a way that survives minification. 
@@ -645,7 +646,7 @@ forEach({
645646      if  ( isObject ( arg1 ) )  { 
646647
647648        // 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 ++ )  { 
649650          if  ( fn  ===  jqLiteData )  { 
650651            // data() takes the whole object in jQuery 
651652            fn ( this [ i ] ,  arg1 ) ; 
@@ -659,9 +660,10 @@ forEach({
659660        return  this ; 
660661      }  else  { 
661662        // we are a read, so read the first child. 
663+         // TODO: do we still need this? 
662664        var  value  =  fn . $dv ; 
663665        // 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 ; 
665667        for  ( var  j  =  0 ;  j  <  jj ;  j ++ )  { 
666668          var  nodeValue  =  fn ( this [ j ] ,  arg1 ,  arg2 ) ; 
667669          value  =  value  ? value  +  nodeValue  : nodeValue ; 
@@ -670,7 +672,7 @@ forEach({
670672      } 
671673    }  else  { 
672674      // we are a write, so apply to all children 
673-       for  ( i  =  0 ;  i  <  this . length ;  i ++ )  { 
675+       for  ( i  =  0 ;  i  <  nodeCount ;  i ++ )  { 
674676        fn ( this [ i ] ,  arg1 ,  arg2 ) ; 
675677      } 
676678      // return self for chaining 
0 commit comments