Last active
September 8, 2016 14:49
-
-
Save leandro/e8b40aaf4727883981255bac62df2d64 to your computer and use it in GitHub Desktop.
Lea Verou's proposal regarding URL class in https://leaverou.github.io/jsux/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!function() { | |
var myURL = function(str) { | |
this.str = str; | |
this.toString = function() { return str; }; | |
} | |
function createFromString(urlString) { | |
return new myURL(urlString); | |
} | |
function createFromURL(url) { | |
return new myURL(url.str); | |
} | |
function createFromLocation(extraURI) { | |
var urlString = window.location.href + (extraURI || ""); | |
return new myURL(urlString); | |
} | |
var myURLFactory = { | |
createFromString: createFromString, | |
createFromURL: createFromURL, | |
createFromLocation: createFromLocation | |
}; | |
window.myURL = myURL; | |
window.myURLFactory = myURLFactory; | |
}(); | |
// > myURLFactory.createFromURL(new myURL("http://abre.ai/")) + "ae" | |
// < "http://abre.ai/ae" | |
// > myURLFactory.createFromString("http://abre.ai/") + "ae" | |
// < "http://abre.ai/ae" | |
// > myURLFactory.createFromLocation("ae") + "opa" | |
// < "http://www.phpied.com/3-ways-to-define-a-javascript-class/aeopa" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment