@@ -20,43 +20,38 @@ 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
+ if ( sourceValue . constructor && sourceValue . constructor . prototype ) {
45
+ targetValue = Object . create ( sourceValue . constructor . prototype ) ;
46
+ } else {
47
+ targetValue = { } ;
48
+ }
49
+ }
53
50
deepAssign ( targetValue , sourceValue ) ;
54
51
}
55
52
} else {
56
-
57
53
targetValue = sourceValue ;
58
54
}
59
-
60
55
_target [ key ] = targetValue ;
61
56
}
62
57
}
@@ -100,7 +95,7 @@ export function getAllPropertyNames(obj: any): string[] {
100
95
obj = Object . getPrototypeOf ( obj ) ;
101
96
} while ( obj !== Object . prototype ) ;
102
97
103
- const exists : { [ name : string ] : boolean | undefined } = { } ;
98
+ const exists : { [ name : string ] : boolean | undefined } = { } ;
104
99
105
100
return names . filter ( name => {
106
101
0 commit comments