使用構造器建立對象
function A1(username,pwd){
this.username = username;
this.pwd = pwd;
this.say = function(){
alert(11);
}
return this;
}
使用factory建立對象
function A2(username,pwd){
var obj = new Object();
obj.username = username;
obj.pwd = pwd;
return obj;
}
使用原型建立對象
function A3(){}
A.prototype.username = "張三";
A.prototype.pwd = "12354";
調用
var a1 = new A1("張珊","123456");
alert(a1.username+"--"+a1.pwd);
var a2 = new A2("張珊","123456");
alert(a2.username+"--"+a2.pwd);
var a3 = new A3();
alert(a.username+"--"+a3.pwd);