Improved Oversimplified.CopyObject to copy arrays by value instead of reference.
This commit is contained in:
parent
74b7eb885d
commit
98280fc465
|
@ -1285,12 +1285,20 @@ Oversimplified.CopyObject = function (object, newID, newName, objectOptions) {
|
||||||
}
|
}
|
||||||
for (var property in object) {
|
for (var property in object) {
|
||||||
if (typeof resultingCopy[property] === 'undefined') {
|
if (typeof resultingCopy[property] === 'undefined') {
|
||||||
resultingCopy[property] = object[property];
|
if (object[property].slice) { // If it's an array, copy its values.
|
||||||
|
resultingCopy[property] = object[property].slice();
|
||||||
|
} else {
|
||||||
|
resultingCopy[property] = object[property];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (var option in objectOptions) {
|
for (var option in objectOptions) {
|
||||||
//Overwrite any properties.
|
//Overwrite any properties.
|
||||||
resultingCopy[option] = objectOptions[option];
|
if (object[option].slice) { // If it's an array, copy its values.
|
||||||
|
resultingCopy[option] = object[option].slice();
|
||||||
|
} else {
|
||||||
|
resultingCopy[option] = objectOptions[option];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return resultingCopy;
|
return resultingCopy;
|
||||||
|
|
Loading…
Reference in New Issue