URLConstructors
URL: Constructors
This interface defines the surface area of expected constructors for standard URL
objects. According to spec, URL objects must be constructable from a plain string
or from another URL
. Empty URLs cannot be constructed; if the provided string
is an invalid URL, it is rejected with an error.
MDN documents the combined constructor as:
"The URL() constructor returns a newly created URL object representing the URL defined by the parameters. If the given base URL or the resulting URL are not valid URLs, the JavaScript TypeError exception is thrown."
Functions
Construct a copy of the provided URL
object. Since the URL
is already parsed, we can easily copy it without validating, as it was validated when it was first constructed.
Construct a new URL
object from the provided string
. If the provided string
is not a valid URL, an error is thrown. The resulting URL can be considered validated and well-formed.