canmove, Confirmed users
2,056
edits
(the URI module) |
(→URI) |
||
Line 119: | Line 119: | ||
The [http://hg.mozdev.org/jsmodules/file/tip/URI.js URI module] creates [http://mxr.mozilla.org/mozilla/source/netwerk/base/public/nsIURI.idl nsIURI] objects from location strings. It wraps [http://mxr.mozilla.org/mozilla/source/netwerk/base/public/nsIIOService.idl nsIIOService]::newURI. There are two ways to use it. First, you can call it as a constructor: | The [http://hg.mozdev.org/jsmodules/file/tip/URI.js URI module] creates [http://mxr.mozilla.org/mozilla/source/netwerk/base/public/nsIURI.idl nsIURI] objects from location strings. It wraps [http://mxr.mozilla.org/mozilla/source/netwerk/base/public/nsIIOService.idl nsIIOService]::newURI. There are two ways to use it. First, you can call it as a constructor: | ||
new URI(spec, charset, baseURI); | let foo = new URI(spec, charset, baseURI); | ||
Second, you can call its <tt>get</tt> method: | Second, you can call its <tt>get</tt> method: | ||
URI.get(spec, charset, baseURI); | let bar = URI.get(spec, charset, baseURI); | ||
In both cases, the parameters are the same, and only the <tt>spec</tt> parameter is required; the <tt>charset</tt> and <tt>baseURI</tt> parameters are optional. The difference between these two techniques is that the constructor throws an error if you pass it an invalid spec, while the <tt>get</tt> method returns null in that case. | In both cases, the parameters are the same, and only the <tt>spec</tt> parameter is required; the <tt>charset</tt> and <tt>baseURI</tt> parameters are optional. The difference between these two techniques is that the constructor throws an error if you pass it an invalid spec, while the <tt>get</tt> method returns null in that case. | ||
In the future, the URI module may return JavaScript URI objects implementing a different interface than nsIURI. | In the future, the URI module may return JavaScript URI objects implementing a different interface than nsIURI. |