locationと同じように使えるURIコンストラクタ。new URI("http://example.com/foo?q=bar#qxx").searchのように使う。
function URI(uri) { uri = String(uri); var parser = /^([^:/?#]+:)?\/\/(([^/?#:]*):?(\d*))?([^?#]*)(\?[^#]*)?(#.*)?$/; var m = uri.match(parser); if (!m) throw new URIError("malformed URI given"); this.href = m[0]; this.protocol = m[1] || ""; this.host = m[2] || ""; this.hostname = m[3] || ""; this.port = m[4] || ""; this.pathname = m[5] || ""; this.search = m[6] === "?" ? "" : m[6] || ""; this.hash = m[7] || ""; } URI.prototype.toString = function () { return this.href; };