From adf23817310ec2d8142895085458fb4ba20d3b98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Fri, 9 Nov 2007 20:13:31 +0000 Subject: [PATCH] Make OpenLayers.Util.applyDefaults() return the modified object. To be consistent with OpenLayers.Util.Extend() and be able to use anonymous object as the 'to' object. Thanks fredj for the patch and tests. Thanks euzuro and crschmidt for the reviews. (closes #992) git-svn-id: http://svn.openlayers.org/trunk/openlayers@5162 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Util.js | 1 + tests/test_Util.html | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index 25f11e2106..9e489557e1 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -503,6 +503,7 @@ OpenLayers.Util.applyDefaults = function (to, from) { to[key] = from[key]; } } + return to; }; /** diff --git a/tests/test_Util.html b/tests/test_Util.html index 48231379a2..32672fea22 100644 --- a/tests/test_Util.html +++ b/tests/test_Util.html @@ -143,7 +143,7 @@ function test_06_Util_applyDefaults(t) { - t.plan(4); + t.plan(8); var to = { 'a': "abra", @@ -161,6 +161,12 @@ t.eq( to["a"], "abra", "key present in to but not from maintained"); t.eq( to["b"], "blorg", "key present in to and from, maintained in to"); t.eq( to["c"], "press", "key present in from and not to successfully copied to to"); + + var ret = OpenLayers.Util.applyDefaults({'a': "abra",'b': "blorg"}, from); + t.ok( ret instanceof Object, " applyDefaults returns an object"); + t.eq( ret["a"], "abra", "key present in ret but not from maintained"); + t.eq( ret["b"], "blorg", "key present in ret and from, maintained in ret"); + t.eq( ret["c"], "press", "key present in from and not ret successfully copied to ret"); } function test_07_Util_getParameterString(t) {