Why does Object.assign not copy the properties of the URL object?

On macOS 10.13.1 with Chrome 63 .

I use Object.assignwith the new URL () as the source object, but does it always give an empty object? This seems like weird behavior. Here is my code:

 let url = new URL('http://www.yahoo.com');
 console.log(url);
 let data = Object.assign({}, url);
 console.log(data);

Why data is an empty object, while it urlhas a full URL, as shown below:

{
 href: "http://www.yahoo.com/", 
 origin: "http://www.yahoo.com", 
 protocol: "http:", 
 username: "", 
 password: ""
 ...
}

I also tried:

let data = Object.assign({}, ...url);  

but he gives:

Uncaught TypeError: undefined is not a function

+6
source share
2 answers

, URL enumerable. , Object.keys(url), ? Object.assign Object.keys enumerable .

URL enumerable.

+5

URL- :

 let url = new URL('http://www.yahoo.com');
 console.log(url);
 let data = new URL(url);
 console.log(data);

URL:

url = new URL(url, [base])

URL , href .

+2

All Articles