I am, for the first time, trying some OO JS. Here is what I've come up with so far:
var myObj = {
1 site_url: window.location.protocol + "//" + window.location.hostname + "/",
2 site_host: window.location.hostname,
3 site_brand: this.readCookie('aCookieName'),
4 site_full_url: this.site_url + window.location.pathname,
5 /***
6 Read a cookie by its name;
7 **/
8
9 readCookie: function(name) {
10 var nameEQ = name + "=";
11 var ca = document.cookie.split(';');
12 for(var i=0;i < ca.length;i++) {
13 var c = ca[i];
14 while (c.charAt(0) == ' ') c = c.substring(1, c.length);
15 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
16 }
17 return null;
18 },
19
20 /***
20 ***/
22 SaySomeThing: function() {
23 alert(this.site_brand);
24 }
}
Bear with me, I am new to this. The problem I have is:
Line # 3 - I get an error: readCookie is undefined;
Line # 4 - Another error: site_url is undefined;
Please help me with the above.