OpenLayers OpenLayers

Changeset 5281

Show
Ignore:
Timestamp:
11/26/07 18:45:43 (1 year ago)
Author:
tschaub
Message:

extend now only sets defined properties on the destination - if your source has a property set to undefined, the destination property will not be set (closes #1160).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Util.js

    r5280 r5281  
    3939 * APIFunction: extend 
    4040 * Copy all properties of a source object to a destination object.  Modifies 
    41  *     the passed in destination object. 
     41 *     the passed in destination object.  Any properties on the source object 
     42 *     that are set to undefined will not be (re)set on the destination object. 
    4243 * 
    4344 * Parameters: 
     
    5152    if(destination && source) { 
    5253        for(var property in source) { 
    53             destination[property] = source[property]; 
     54            value = source[property]; 
     55            if(value !== undefined) { 
     56                destination[property] = value; 
     57            } 
    5458        } 
    5559        /** 
  • trunk/openlayers/tests/test_Util.html

    r5280 r5281  
    592592 
    593593    function tests_Util_extend(t) { 
    594         t.plan(5); 
     594        t.plan(6); 
    595595 
    596596        var source = { 
     
    604604            toString: function() { 
    605605                return "source"; 
    606             } 
    607         }; 
    608         var destination = OpenLayers.Util.extend({}, source); 
     606            }, 
     607            nada: undefined 
     608        }; 
     609        var destination = OpenLayers.Util.extend({nada: "untouched"}, source); 
    609610        t.eq(destination.num, source.num, 
    610611             "extend properly sets primitive property on destination"); 
     
    615616        t.eq(destination.toString(), "source", 
    616617             "extend properly sets custom toString method"); 
     618        t.eq(destination.nada, "untouched", 
     619             "undefined source properties don't clobber existing properties"); 
    617620        t.eq(window.property, undefined, "Property variable not clobbered."); 
    618621    }