NewClass.prototype.ChangeName("鄭運濤"); document.write(NewClass.Name); //undefined,即未定義 document.write(NewClass.prototype.Name); //鄭運濤 var Wo = new NewClass(); document.write(Wo.Name); //泣紅亭
function WuYouUser() { this.Name = "泣紅亭"; return; this.Sex = "男"; } var Wo = new WuYouUser(); document.write(Wo.Name); //泣紅亭 document.write(Wo.Sex); //undefined,即未定義
定義一個類: function WuYouUser() { this.Name = "泣紅亭"; }
定義類作為一個對象時的屬性:
WuYouUser.Url = "http://www.51js.com"; //靜態屬性的定義是:WuYouUser.prototype.Url = "http://www.51js.com"; var Wo = new WuYouUser(); document.write(WuYouUser.Url); //http://www.51js.com document.write(Wo.Url); //undefined,即未定義!注意這里的未定義