@@ -881,22 +881,10 @@ function copy(source, destination) {
881
881
}
882
882
883
883
var needsRecurse = false ;
884
- var destination ;
884
+ var destination = copyType ( source ) ;
885
885
886
- if ( isArray ( source ) ) {
887
- destination = [ ] ;
888
- needsRecurse = true ;
889
- } else if ( isTypedArray ( source ) ) {
890
- destination = new source . constructor ( source ) ;
891
- } else if ( isDate ( source ) ) {
892
- destination = new Date ( source . getTime ( ) ) ;
893
- } else if ( isRegExp ( source ) ) {
894
- destination = new RegExp ( source . source , source . toString ( ) . match ( / [ ^ \/ ] * $ / ) [ 0 ] ) ;
895
- destination . lastIndex = source . lastIndex ;
896
- } else if ( isFunction ( source . cloneNode ) ) {
897
- destination = source . cloneNode ( true ) ;
898
- } else {
899
- destination = Object . create ( getPrototypeOf ( source ) ) ;
886
+ if ( destination === undefined ) {
887
+ destination = isArray ( source ) ? [ ] : Object . create ( getPrototypeOf ( source ) ) ;
900
888
needsRecurse = true ;
901
889
}
902
890
@@ -907,6 +895,36 @@ function copy(source, destination) {
907
895
? copyRecurse ( source , destination )
908
896
: destination ;
909
897
}
898
+
899
+ function copyType ( source ) {
900
+ switch ( toString . call ( source ) ) {
901
+ case '[object Int8Array]' :
902
+ case '[object Int16Array]' :
903
+ case '[object Int32Array]' :
904
+ case '[object Float32Array]' :
905
+ case '[object Float64Array]' :
906
+ case '[object Uint8Array]' :
907
+ case '[object Uint8ClampedArray]' :
908
+ case '[object Uint16Array]' :
909
+ case '[object Uint32Array]' :
910
+ return new source . constructor ( source ) ;
911
+
912
+ case '[object Boolean]' :
913
+ case '[object Number]' :
914
+ case '[object String]' :
915
+ case '[object Date]' :
916
+ return new source . constructor ( source . valueOf ( ) ) ;
917
+
918
+ case '[object RegExp]' :
919
+ var re = new RegExp ( source . source , source . toString ( ) . match ( / [ ^ \/ ] * $ / ) [ 0 ] ) ;
920
+ re . lastIndex = source . lastIndex ;
921
+ return re ;
922
+ }
923
+
924
+ if ( isFunction ( source . cloneNode ) ) {
925
+ return source . cloneNode ( true ) ;
926
+ }
927
+ }
910
928
}
911
929
912
930
/**
0 commit comments