a simple hack with the first answer
var getLocation = function(href=window.location.href) {
var l = document.createElement("a");
l.href = href;
return l;
};
this can used even without argument to figure out the current hostname
getLocation().hostname will give current hostname