#837 - modify Util.extend to deal with custom toString property - IE doesn't iterate over toString, this patch fixes this behavior for Util.extend
git-svn-id: http://svn.openlayers.org/trunk/openlayers@3760 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -36,12 +36,30 @@ if ($ == null) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function: extend
|
* APIFunction: extend
|
||||||
* From Prototype.js
|
* Copy all properties of a source object to a destination object. Modifies
|
||||||
|
* the passed in destination object.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* destination - {Object} The object that will be modified
|
||||||
|
* source - {Object} The object with properties to be set on the destination
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Object} The destination object.
|
||||||
*/
|
*/
|
||||||
OpenLayers.Util.extend = function(destination, source) {
|
OpenLayers.Util.extend = function(destination, source) {
|
||||||
for (property in source) {
|
if(destination && source) {
|
||||||
destination[property] = source[property];
|
for(property in source) {
|
||||||
|
destination[property] = source[property];
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* IE doesn't include the toString property when iterating over an object's
|
||||||
|
* properties with the for(property in object) syntax. Explicitly check if
|
||||||
|
* the source has its own toString property.
|
||||||
|
*/
|
||||||
|
if(source.hasOwnProperty && source.hasOwnProperty('toString')) {
|
||||||
|
destination.toString = source.toString;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return destination;
|
return destination;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -578,7 +578,33 @@
|
|||||||
t.eq(OpenLayers.Util.getArgs('http://www.example.com?foo=bar#bugssucks'),
|
t.eq(OpenLayers.Util.getArgs('http://www.example.com?foo=bar#bugssucks'),
|
||||||
{'foo': 'bar'}, "getArgs works when using a fragment identifier");
|
{'foo': 'bar'}, "getArgs works when using a fragment identifier");
|
||||||
}
|
}
|
||||||
// -->
|
|
||||||
|
function tests_Util_extend(t) {
|
||||||
|
t.plan(4);
|
||||||
|
var source = {
|
||||||
|
num: Math.random(),
|
||||||
|
obj: {
|
||||||
|
foo: "bar"
|
||||||
|
},
|
||||||
|
method: function() {
|
||||||
|
return "method";
|
||||||
|
},
|
||||||
|
toString: function() {
|
||||||
|
return "source";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var destination = OpenLayers.Util.extend({}, source);
|
||||||
|
t.eq(destination.num, source.num,
|
||||||
|
"extend properly sets primitive property on destination");
|
||||||
|
t.eq(destination.obj, source.obj,
|
||||||
|
"extend properly sets object property on destination");
|
||||||
|
t.eq(destination.method(), "method",
|
||||||
|
"extend properly sets function property on destination");
|
||||||
|
t.eq(destination.toString(), "source",
|
||||||
|
"extend properly sets custom toString method");
|
||||||
|
}
|
||||||
|
|
||||||
|
// -->
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
Reference in New Issue
Block a user