I have this Code, and it's working.
var URL = new Object();
URL.pattern = /https?:\/\/([^\/]*)\//;
URL.current = window.location.href;
URL.getCurrent = function(){
return this.current.match(this.pattern)[1];
};
var thisDomain = URL.getCurrent();
Now what I want is to put the dot notations into the object, how do I do that? I tried this, but it's showing undefined when I call URL.getCurrent().
function URL(){
this.pattern = /https?:\/\/([^\/]*)\//;
this.current = window.location.href;
this.getCurrent = function(){
return this.current.match(this.pattern)[1];
};
}
I hope someone can help me out.
The easiest thing you could do, is putting it n an object literal.
http://jsfiddle.net/wJQb6/
var URL = {
pattern: /https?:\/\/([^\/]*)\//,
current: window.location.href,
getCurrent: function () {
return this.current.match(this.pattern)[1];
}
}
alert(URL.getCurrent());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With