(inObject)
| 17 | * @return {object} A deep copy of the original object or array. |
| 18 | */ |
| 19 | var DeepCopy = function (inObject) |
| 20 | { |
| 21 | var outObject; |
| 22 | var value; |
| 23 | var key; |
| 24 | |
| 25 | if (typeof inObject !== 'object' || inObject === null) |
| 26 | { |
| 27 | // inObject is not an object |
| 28 | return inObject; |
| 29 | } |
| 30 | |
| 31 | // Create an array or object to hold the values |
| 32 | outObject = Array.isArray(inObject) ? [] : {}; |
| 33 | |
| 34 | for (key in inObject) |
| 35 | { |
| 36 | value = inObject[key]; |
| 37 | |
| 38 | // Recursively (deep) copy for nested objects, including arrays |
| 39 | outObject[key] = DeepCopy(value); |
| 40 | } |
| 41 | |
| 42 | return outObject; |
| 43 | }; |
| 44 | |
| 45 | module.exports = DeepCopy; |
no outgoing calls
no test coverage detected
searching dependent graphs…