<Script type = "text/javascript">
// Factory Mode
Function person (name, age, add ){
Var o = new Object ();
O. name = name;
O. age = age;
O. add = add;
O. smay = function (){
Alert (o. name );
}
Return o;
}
Var person1 = person ('xioawang ', 25, 'beijing ');
Person1.smay ();
</Script>
<Script type = "text/javascript">
// Constructor
Function Person (name1, age1, add1 ){
This. name1 = name1;
This. age1 = age1;
This. add1 = add1;
This. smay1 = function (){
Alert (this. name1 );
}
}
Var person2 = new Person ('xiaoli', 25, 'handand ');
Person2.smay1 ();
</Script>
<Script type = "text/javascript">
// Prototype
Function person11 (name2, age2, add2 ){
Person11.prototype. name2 = 'xiaozhang ';
Person11.prototype. age2 = 15;
Person11.prototype. add2 = 'hebei ';
Person11.prototype. saym2 = function (){
Alert (person11.prototype. name2 );
}
}
Var person22 = new person11 ();
Person22.saym2 ();
Var person33 = new person11 ();
Person33.saym2 ();
Alert (person11.prototype. isPrototypeOf (person22 ));
</Script>
<Script type = "text/javascript">
// Simpler Prototype Method
Function person111 (){
}
Person111.prototype = {
Name222: 'xiaowang ',
Age222: 25,
Add222: 'beijing ',
Smay222: function (){
Alert (this. name222 );
}
}
Var person333 = new person111;
Person333.smay222 ();
</Script>
From baikaishui1989