@@ -20,43 +20,34 @@ export function deepAssign(target: any, ...sources: any[]): any {
20
20
return target ;
21
21
22
22
function assign ( key : string | number , _target : any , _source : any ) : void {
23
-
24
23
const sourceValue = _source [ key ] ;
25
- if ( sourceValue !== void 0 ) {
26
24
25
+ if ( sourceValue !== void 0 ) {
27
26
let targetValue = _target [ key ] ;
28
27
29
28
if ( Array . isArray ( sourceValue ) ) {
30
-
31
29
if ( ! Array . isArray ( targetValue ) ) {
32
30
targetValue = [ ] ;
33
31
}
34
-
35
32
const length = targetValue . length ;
36
33
37
34
sourceValue . forEach ( ( _ , index ) => assign ( length + index , targetValue , sourceValue ) ) ;
38
-
39
35
} else if ( typeof sourceValue === 'object' ) {
40
-
41
- targetValue = targetValue || { } ;
42
-
43
36
if ( sourceValue instanceof RegExp ) {
44
-
45
37
targetValue = cloneRegExp ( sourceValue ) ;
46
38
} else if ( sourceValue instanceof Date ) {
47
-
48
39
targetValue = new Date ( sourceValue ) ;
49
40
} else if ( sourceValue === null ) {
50
-
51
41
targetValue = null ;
52
42
} else {
43
+ if ( ! targetValue ) {
44
+ targetValue = Object . create ( sourceValue . constructor . prototype ) ;
45
+ }
53
46
deepAssign ( targetValue , sourceValue ) ;
54
47
}
55
48
} else {
56
-
57
49
targetValue = sourceValue ;
58
50
}
59
-
60
51
_target [ key ] = targetValue ;
61
52
}
62
53
}
@@ -100,7 +91,7 @@ export function getAllPropertyNames(obj: any): string[] {
100
91
obj = Object . getPrototypeOf ( obj ) ;
101
92
} while ( obj !== Object . prototype ) ;
102
93
103
- const exists : { [ name : string ] : boolean | undefined } = { } ;
94
+ const exists : { [ name : string ] : boolean | undefined } = { } ;
104
95
105
96
return names . filter ( name => {
106
97
0 commit comments