File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /**
2+ * @author Richard Davey <rich@photonstorm.com>
3+ * @copyright 2020 Photon Storm Ltd.
4+ * @license {@link https://opensource.org/licenses/MIT|MIT License }
5+ */
6+
7+ /**
8+ * Deep Copy the given object or array.
9+ *
10+ * @function Phaser.Utils.Objects.DeepCopy
11+ * @since 3.50.0
12+ *
13+ * @param {object } obj - The object to deep copy.
14+ *
15+ * @return {object } A deep copy of the original object.
16+ */
17+ var DeepCopy = function ( inObject )
18+ {
19+ var outObject ;
20+ var value ;
21+ var key ;
22+
23+ if ( typeof inObject !== 'object' || inObject === null )
24+ {
25+ // inObject is not an object
26+ return inObject ;
27+ }
28+
29+ // Create an array or object to hold the values
30+ outObject = Array . isArray ( inObject ) ? [ ] : { } ;
31+
32+ for ( key in inObject )
33+ {
34+ value = inObject [ key ] ;
35+
36+ // Recursively (deep) copy for nested objects, including arrays
37+ outObject [ key ] = DeepCopy ( value ) ;
38+ }
39+
40+ return outObject ;
41+ } ;
42+
43+ module . exports = DeepCopy ;
Original file line number Diff line number Diff line change 1111module . exports = {
1212
1313 Clone : require ( './Clone' ) ,
14+ DeepCopy : require ( './DeepCopy' ) ,
1415 Extend : require ( './Extend' ) ,
1516 GetAdvancedValue : require ( './GetAdvancedValue' ) ,
1617 GetFastValue : require ( './GetFastValue' ) ,
You can’t perform that action at this time.
0 commit comments