日期:2014-05-16 浏览次数:20345 次
function createObject(){ var object = new Object(); object.name = "lisi"; object.password = "123456"; object.get = function(){ alert(this.name + ", " + this.password); }; return object; } var object1 = createObject(); object1.get(); var object2 = createObject(); object2.get();
function createObject(){ var object = new Object(); object.name = "lisi"; object.password = "123456"; object.get = get; return object; } function get(){ alert(this.name + ", " + this.password); } var object1 = createObject(); object1.get(); var object2 = createObject(); object2.get();
function Person(username,password){ this.username = username; this.password = password; this.get = function(){ alert(this.username + ", " + this.password); } } var person = new Person("lisi","123456"); person.get();
function Person(){} Person.prototype.username = new Array(); Person.prototype.password = "123"; Person.prototype.getInfo = function(){ alert(this.username + ", " + this.password); } var person1 = new Person(); person1.username.push("zhansan"); person1.username.push("lisi"); person1.password = "456"; person1.getInfo(); var person2 = new Person(); person2.getInfo();
function Person(){ this.username = new Array(); this.password = "123456"; } Person.prototype.get = function(){ alert(this.username + ", " + this.password); } var p1 = new Person(); p1.username.push("zhansan"); p1.get(); var p2 = new Person(); p2.username.push("lisi"); p2.get();
function Person(){ this.username = "zhansan"; this.password = "123456"; if(typeof Person.flag == "undefined"){ Person.prototype.getInfo = function(){ alert(this.username + ", " + this.password); }; Person.flag = true; } } var p1 = new Person(); p1.getInfo(); var p2 = new Person(); p2.getInfo();