2424const {
2525 Boolean,
2626 Int8Array,
27+ ObjectAssign,
2728 ObjectKeys,
2829 StringPrototypeCharCodeAt,
2930 decodeURIComponent,
@@ -735,11 +736,7 @@ Url.prototype.resolveObject = function resolveObject(relative) {
735736 }
736737
737738 const result = new Url ( ) ;
738- const tkeys = ObjectKeys ( this ) ;
739- for ( let tk = 0 ; tk < tkeys . length ; tk ++ ) {
740- const tkey = tkeys [ tk ] ;
741- result [ tkey ] = this [ tkey ] ;
742- }
739+ ObjectAssign ( result , this ) ;
743740
744741 // Hash is always overridden, no matter what.
745742 // even href="" will remove it.
@@ -754,12 +751,13 @@ Url.prototype.resolveObject = function resolveObject(relative) {
754751 // Hrefs like //foo/bar always cut to the protocol.
755752 if ( relative . slashes && ! relative . protocol ) {
756753 // Take everything except the protocol from relative
757- const rkeys = ObjectKeys ( relative ) ;
758- for ( let rk = 0 ; rk < rkeys . length ; rk ++ ) {
759- const rkey = rkeys [ rk ] ;
760- if ( rkey !== 'protocol' )
761- result [ rkey ] = relative [ rkey ] ;
762- }
754+ const relativeWithoutProtocol = ObjectKeys ( relative ) . reduce ( ( acc , key ) => {
755+ if ( key !== 'protocol' ) {
756+ acc [ key ] = relative [ key ] ;
757+ }
758+ return acc ;
759+ } , { } ) ;
760+ ObjectAssign ( result , relativeWithoutProtocol ) ;
763761
764762 // urlParse appends trailing / to urls like http://www.example.com
765763 if ( slashedProtocol . has ( result . protocol ) &&
@@ -781,11 +779,7 @@ Url.prototype.resolveObject = function resolveObject(relative) {
781779 // because that's known to be hostless.
782780 // anything else is assumed to be absolute.
783781 if ( ! slashedProtocol . has ( relative . protocol ) ) {
784- const keys = ObjectKeys ( relative ) ;
785- for ( let v = 0 ; v < keys . length ; v ++ ) {
786- const k = keys [ v ] ;
787- result [ k ] = relative [ k ] ;
788- }
782+ ObjectAssign ( result , relative ) ;
789783 result . href = result . format ( ) ;
790784 return result ;
791785 }
0 commit comments