Improved Oversimplified.CopyObject to copy arrays by value instead of reference.

This commit is contained in:
Robbie Antenesse 2016-04-14 14:54:25 -06:00
parent 74b7eb885d
commit 98280fc465
1 changed files with 10 additions and 2 deletions

View File

@ -1285,12 +1285,20 @@ Oversimplified.CopyObject = function (object, newID, newName, objectOptions) {
}
for (var property in object) {
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) {
//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;