Bug Tracker

Ticket #2616: map[5753].diff

File map[5753].diff, 1.1 kB (added by flesler, 7 months ago)

Updated to match against [5753]

  • jquery/src/core.js

     
    12011201        return ret; 
    12021202    }, 
    12031203 
    1204     map: function( elems, callback ) { 
    1205         var ret = []; 
    1206  
     1204    map: function( source, callback, target ) {  
     1205        if( !target )  
     1206            target = 'length' in source ? [ ] : { };  
     1207         
     1208        if( 'length' in target ){ // Is it an array(-like) ? else a hash  
     1209            var arr = true;  
     1210            if( !target.concat )// Fix array-like objects, or they will fail the final concat  
     1211                target = jQuery.makeArray(target);  
     1212        }  
    12071213        // Go through the items, translating each of the items to their 
    12081214        // new value (or values). 
    1209         for ( var i = 0, length = elems.length; i < length; i++ ) { 
    1210             var value = callback( elems[ i ], i ); 
     1215        jQuery.each( source , function( key, value ){  
     1216            value = callback( value, key );  
     1217         
     1218            if ( value != null )  
     1219                target[ arr ? target.length : key ] = value;  
     1220        });  
    12111221 
    1212             if ( value != null ) 
    1213                 ret[ ret.length ] = value; 
    1214         } 
    1215  
    1216         return ret.concat.apply( [], ret ); 
     1222        return arr ? target.concat.apply( [], target ) : target; 
    12171223    } 
    12181224}); 
    12191225