Changeset 5280
- Timestamp:
- 11/26/07 23:34:50 (1 year ago)
- Files:
-
- trunk/openlayers/lib/OpenLayers/Util.js (modified) (1 diff)
- trunk/openlayers/tests/test_Util.html (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/lib/OpenLayers/Util.js
r5162 r5280 490 490 /** 491 491 * Function: applyDefaults 492 * Takes a hashtable and copies any keys that don't exist from493 * another hashtable, by analogy with OpenLayers.Util.extend() from492 * Takes an object and copies any properties that don't exist from 493 * another properties, by analogy with OpenLayers.Util.extend() from 494 494 * Prototype.js. 495 495 * 496 496 * Parameters: 497 * to - {Object} 498 * from - {Object} 497 * to - {Object} The destination object. 498 * from - {Object} The source object. Any properties of this object that 499 * are undefined in the to object will be set on the to object. 500 * 501 * Returns: 502 * {Object} A reference to the to object. Note that the to argument is modified 503 * in place and returned by this function. 499 504 */ 500 505 OpenLayers.Util.applyDefaults = function (to, from) { 501 506 for (var key in from) { 502 if (to[key] == null) { 507 if (to[key] === undefined || 508 (from.hasOwnProperty 509 && from.hasOwnProperty(key) && !to.hasOwnProperty(key))) { 503 510 to[key] = from[key]; 504 511 } 505 512 } 513 /** 514 * IE doesn't include the toString property when iterating over an object's 515 * properties with the for(property in object) syntax. Explicitly check if 516 * the source has its own toString property. 517 */ 518 if(from.hasOwnProperty 519 && from.hasOwnProperty('toString') && !to.hasOwnProperty('toString')) { 520 to.toString = from.toString; 521 } 522 506 523 return to; 507 524 }; trunk/openlayers/tests/test_Util.html
r5162 r5280 142 142 } 143 143 144 function test_ 06_Util_applyDefaults(t) {145 146 t.plan( 8);144 function test_Util_applyDefaults(t) { 145 146 t.plan(10); 147 147 148 148 var to = { 149 149 'a': "abra", 150 'b': "blorg" 150 'b': "blorg", 151 'n': null 151 152 }; 152 153 153 154 var from = { 154 155 'b': "zoink", 155 'c': "press" 156 'c': "press", 157 'toString': function() {return 'works'}, 158 'n': "broken" 156 159 }; 157 160 … … 168 171 t.eq( ret["b"], "blorg", "key present in ret and from, maintained in ret"); 169 172 t.eq( ret["c"], "press", "key present in from and not ret successfully copied to ret"); 173 t.eq(to.toString(), "works", "correctly applies custom toString"); 174 t.eq(to.n, null, "correctly preserves null"); 170 175 } 171 176
