From 98280fc46512a45f233da3f3013b48e03172b719 Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Thu, 14 Apr 2016 14:54:25 -0600 Subject: [PATCH] Improved Oversimplified.CopyObject to copy arrays by value instead of reference. --- Oversimplified.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Oversimplified.js b/Oversimplified.js index f28cc88..7710f6a 100644 --- a/Oversimplified.js +++ b/Oversimplified.js @@ -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;