forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeepCopy.js
More file actions
43 lines (36 loc) · 963 Bytes
/
Copy pathDeepCopy.js
File metadata and controls
43 lines (36 loc) · 963 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
/**
* Deep Copy the given object or array.
*
* @function Phaser.Utils.Objects.DeepCopy
* @since 3.50.0
*
* @param {object} obj - The object to deep copy.
*
* @return {object} A deep copy of the original object.
*/
var DeepCopy = function (inObject)
{
var outObject;
var value;
var key;
if (typeof inObject !== 'object' || inObject === null)
{
// inObject is not an object
return inObject;
}
// Create an array or object to hold the values
outObject = Array.isArray(inObject) ? [] : {};
for (key in inObject)
{
value = inObject[key];
// Recursively (deep) copy for nested objects, including arrays
outObject[key] = DeepCopy(value);
}
return outObject;
};
module.exports = DeepCopy;