我第一次尝试使用面向对象的JavaScript编程。以下是我目前的代码:
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 }
}
请您耐心等待,我是一名新手。我遇到的问题是:
第3行 - 我遇到了一个错误:readCookie未定义;
第4行 - 另外一个错误:site_url未定义;
请帮我解决以上问题。