@@ -101,7 +101,7 @@ that an effort will be made to coerce the given values into strings. For
101101instance:
102102
103103``` js
104- const myURL = new URL ({toString : () => ' https://example.org/' });
104+ const myURL = new URL ({ toString : () => ' https://example.org/' });
105105 // https://example.org/
106106```
107107
@@ -186,6 +186,7 @@ console.log(myURL.href);
186186 // Prints https://example.org/foo
187187
188188myURL .href = ' https://example.com/bar' ;
189+ console .log (myURL .href );
189190 // Prints https://example.com/bar
190191```
191192
@@ -332,7 +333,7 @@ console.log(myURL.protocol);
332333
333334myURL .protocol = ' ftp' ;
334335console .log (myURL .href );
335- // Prints ftp://example.org
336+ // Prints ftp://example.org/
336337```
337338
338339Invalid URL protocol values assigned to the ` protocol ` property are ignored.
@@ -380,7 +381,7 @@ console.log(myURL.username);
380381
381382myURL .username = ' 123' ;
382383console .log (myURL .href );
383- // Prints https://123:xyz@example.com
384+ // Prints https://123:xyz@example.com/
384385```
385386
386387Any invalid URL characters appearing in the value assigned the ` username `
@@ -515,7 +516,7 @@ const params = new URLSearchParams({
515516 query: [' first' , ' second' ]
516517});
517518console .log (params .getAll (' query' ));
518- // Prints ['first,second']
519+ // Prints [ 'first,second' ]
519520console .log (params .toString ());
520521 // Prints 'user=abc&query=first%2Csecond'
521522```
@@ -571,7 +572,8 @@ console.log(params.toString());
571572new URLSearchParams ([
572573 [' user' , ' abc' , ' error' ]
573574]);
574- // Throws TypeError: Each query pair must be a name/value tuple
575+ // Throws TypeError [ERR_INVALID_TUPLE]:
576+ // Each query pair must be an iterable [name, value] tuple
575577```
576578
577579#### urlSearchParams.append(name, value)
@@ -816,8 +818,8 @@ console.log(myURL.href);
816818console .log (myURL .toString ());
817819 // Prints https://a:b@xn--6qqa088eba/?abc#foo
818820
819- console .log (url .format (myURL, {fragment: false , unicode: true , auth: false }));
820- // Prints 'https://你好你好?abc'
821+ console .log (url .format (myURL, { fragment: false , unicode: true , auth: false }));
822+ // Prints 'https://你好你好/ ?abc'
821823```
822824
823825## Legacy URL API
0 commit comments