@@ -20,43 +20,34 @@ export function deepAssign(target: any, ...sources: any[]): any {
2020 return target ;
2121
2222 function assign ( key : string | number , _target : any , _source : any ) : void {
23-
2423 const sourceValue = _source [ key ] ;
25- if ( sourceValue !== void 0 ) {
2624
25+ if ( sourceValue !== void 0 ) {
2726 let targetValue = _target [ key ] ;
2827
2928 if ( Array . isArray ( sourceValue ) ) {
30-
3129 if ( ! Array . isArray ( targetValue ) ) {
3230 targetValue = [ ] ;
3331 }
34-
3532 const length = targetValue . length ;
3633
3734 sourceValue . forEach ( ( _ , index ) => assign ( length + index , targetValue , sourceValue ) ) ;
38-
3935 } else if ( typeof sourceValue === 'object' ) {
40-
41- targetValue = targetValue || { } ;
42-
4336 if ( sourceValue instanceof RegExp ) {
44-
4537 targetValue = cloneRegExp ( sourceValue ) ;
4638 } else if ( sourceValue instanceof Date ) {
47-
4839 targetValue = new Date ( sourceValue ) ;
4940 } else if ( sourceValue === null ) {
50-
5141 targetValue = null ;
5242 } else {
43+ if ( ! targetValue ) {
44+ targetValue = Object . create ( sourceValue . constructor . prototype ) ;
45+ }
5346 deepAssign ( targetValue , sourceValue ) ;
5447 }
5548 } else {
56-
5749 targetValue = sourceValue ;
5850 }
59-
6051 _target [ key ] = targetValue ;
6152 }
6253 }
@@ -100,7 +91,7 @@ export function getAllPropertyNames(obj: any): string[] {
10091 obj = Object . getPrototypeOf ( obj ) ;
10192 } while ( obj !== Object . prototype ) ;
10293
103- const exists : { [ name : string ] : boolean | undefined } = { } ;
94+ const exists : { [ name : string ] : boolean | undefined } = { } ;
10495
10596 return names . filter ( name => {
10697
0 commit comments