Changeset 4447
- Timestamp:
- 01/14/08 20:06:34 (6 months ago)
- Location:
- trunk/jquery
- Files:
-
- 2 modified
-
src/core.js (modified) (2 diffs)
-
test/unit/core.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/jquery/src/core.js
r4444 r4447 708 708 each: function( object, callback, args ) { 709 709 if ( args ) { 710 if ( object.length == undefined ) 710 if ( object.length == undefined ) { 711 711 for ( var name in object ) 712 callback.apply( object[ name ], args ); 713 else 712 if ( callback.apply( object[ name ], args ) === false ) 713 break; 714 } else 714 715 for ( var i = 0, length = object.length; i < length; i++ ) 715 716 if ( callback.apply( object[ i ], args ) === false ) … … 718 719 // A special, fast, case for the most common use of each 719 720 } else { 720 if ( object.length == undefined ) 721 if ( object.length == undefined ) { 721 722 for ( var name in object ) 722 callback.call( object[ name ], name, object[ name ] ); 723 else 723 if ( callback.call( object[ name ], name, object[ name ] ) === false ) 724 break; 725 } else 724 726 for ( var i = 0, length = object.length, value = object[0]; 725 727 i < length && callback.call( value, i, value ) !== false; value = object[++i] ){} -
trunk/jquery/test/unit/core.js
r4441 r4447 1315 1315 1316 1316 test("$.each(Object,Function)", function() { 1317 expect( 8);1317 expect(12); 1318 1318 $.each( [0,1,2], function(i, n){ 1319 1319 ok( i == n, "Check array iteration" ); … … 1327 1327 ok( i == n, "Check object iteration" ); 1328 1328 }); 1329 1330 var total = 0; 1331 jQuery.each([1,2,3], function(i,v){ total += v; }); 1332 ok( total == 6, "Looping over an array" ); 1333 total = 0; 1334 jQuery.each([1,2,3], function(i,v){ total += v; if ( i == 1 ) return false; }); 1335 ok( total == 3, "Looping over an array, with break" ); 1336 total = 0; 1337 jQuery.each({"a":1,"b":2,"c":3}, function(i,v){ total += v; }); 1338 ok( total == 6, "Looping over an object" ); 1339 total = 0; 1340 jQuery.each({"a":3,"b":3,"c":3}, function(i,v){ total += v; return false; }); 1341 ok( total == 3, "Looping over an object, with break" ); 1329 1342 }); 1330 1343