Changeset 5281
- Timestamp:
- 11/26/07 18:45:43 (1 year ago)
- Files:
-
- trunk/openlayers/lib/OpenLayers/Util.js (modified) (2 diffs)
- trunk/openlayers/tests/test_Util.html (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/lib/OpenLayers/Util.js
r5280 r5281 39 39 * APIFunction: extend 40 40 * 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. 42 43 * 43 44 * Parameters: … … 51 52 if(destination && source) { 52 53 for(var property in source) { 53 destination[property] = source[property]; 54 value = source[property]; 55 if(value !== undefined) { 56 destination[property] = value; 57 } 54 58 } 55 59 /** trunk/openlayers/tests/test_Util.html
r5280 r5281 592 592 593 593 function tests_Util_extend(t) { 594 t.plan( 5);594 t.plan(6); 595 595 596 596 var source = { … … 604 604 toString: function() { 605 605 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); 609 610 t.eq(destination.num, source.num, 610 611 "extend properly sets primitive property on destination"); … … 615 616 t.eq(destination.toString(), "source", 616 617 "extend properly sets custom toString method"); 618 t.eq(destination.nada, "untouched", 619 "undefined source properties don't clobber existing properties"); 617 620 t.eq(window.property, undefined, "Property variable not clobbered."); 618 621 }
