@@ -101,7 +101,7 @@ that an effort will be made to coerce the given values into strings. For
101
101
instance:
102
102
103
103
``` js
104
- const myURL = new URL ({toString : () => ' https://example.org/' });
104
+ const myURL = new URL ({ toString : () => ' https://example.org/' });
105
105
// https://example.org/
106
106
```
107
107
@@ -186,6 +186,7 @@ console.log(myURL.href);
186
186
// Prints https://example.org/foo
187
187
188
188
myURL .href = ' https://example.com/bar' ;
189
+ console .log (myURL .href );
189
190
// Prints https://example.com/bar
190
191
```
191
192
@@ -332,7 +333,7 @@ console.log(myURL.protocol);
332
333
333
334
myURL .protocol = ' ftp' ;
334
335
console .log (myURL .href );
335
- // Prints ftp://example.org
336
+ // Prints ftp://example.org/
336
337
```
337
338
338
339
Invalid URL protocol values assigned to the ` protocol ` property are ignored.
@@ -380,7 +381,7 @@ console.log(myURL.username);
380
381
381
382
myURL .username = ' 123' ;
382
383
console .log (myURL .href );
383
- // Prints https://123:[email protected]
384
+ // Prints https://123:[email protected] /
384
385
```
385
386
386
387
Any invalid URL characters appearing in the value assigned the ` username `
@@ -515,7 +516,7 @@ const params = new URLSearchParams({
515
516
query: [' first' , ' second' ]
516
517
});
517
518
console .log (params .getAll (' query' ));
518
- // Prints ['first,second']
519
+ // Prints [ 'first,second' ]
519
520
console .log (params .toString ());
520
521
// Prints 'user=abc&query=first%2Csecond'
521
522
```
@@ -571,7 +572,8 @@ console.log(params.toString());
571
572
new URLSearchParams ([
572
573
[' user' , ' abc' , ' error' ]
573
574
]);
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
575
577
```
576
578
577
579
#### urlSearchParams.append(name, value)
@@ -816,8 +818,8 @@ console.log(myURL.href);
816
818
console .log (myURL .toString ());
817
819
// Prints https://a:b@xn--6qqa088eba/?abc#foo
818
820
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'
821
823
```
822
824
823
825
## Legacy URL API
0 commit comments