Create applyDefaults() function that works similarly to extend(), but without replacing existing keys.

git-svn-id: http://svn.openlayers.org/trunk/openlayers@111 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Schuyler Erle
2006-05-17 20:57:05 +00:00
parent 6c5b85626e
commit 11e66c0286

View File

@@ -604,3 +604,20 @@ OpenLayers.getParameterString = function(params) {
OpenLayers.Util.getImagesLocation = function () {
return "img/";
};
/** Takes a hash and copies any keys that don't exist from
* another hash, by analogy with Object.extend() from
* Prototype.js.
*
* @param {Object} to
* @param {Object} from
* @return {Object}
*/
OpenLayers.Util.applyDefaults = function (to, from) {
for (var key in from) {
if (to[key] == null) {
to[key] = from[key];
}
}
return to;
};