1. "text/javascript">  
  2.       
  3.     function Person(username)  
  4.     {  
  5.         this.username = username  
  6.           
  7.         this.sexy = function()  
  8.         {  
  9.             alert("Are u sexy?");  
  10.         }  
  11.           
  12.         Person.prototype.pizza = function()  
  13.         {  
  14.             alert("Would you like a pizza?");  
  15.         }  
  16.           
  17.         if (typeof Person.flag == "undefined")  
  18.         {  
  19.             alert("START");  
  20.               
  21.             Person.prototype.getInfo = function()  
  22.             {  
  23.                 alert("Here: " + this.username);  
  24.             }  
  25.               
  26.             Person.flag = true;  
  27.         }  
  28.     }  
  29.       
  30.     function women(username, age)  
  31.     {  
  32.         this.method1 = Person;  
  33.         //Without 'this', it does not work  
  34.         this.method1(username);  
  35.         delete this.method1;  
  36.           
  37.         this.age = age;  
  38.           
  39.         if(typeof women.flag == "undefined")  
  40.         {  
  41.             alert("women");  
  42.             women.prototype.sayWorld = function()  
  43.             {  
  44.                 alert("woman: "+ username + " " + age);  
  45.             }  
  46.             women.flag=true;  
  47.         }  
  48.     }  
  49.       
  50.     function Child(username, age)  
  51.     {  
  52.         Person.call(this, username);  
  53.     }  
  54.       
  55.     function Child2(username)  
  56.     {  
  57.         //Similar as call, but from the second args, apply accept array  
  58.         Person.apply(this,new Array(username));  
  59.     }  
  60.       
  61.     function Child3()  
  62.     {  
  63.     }  
  64.       
  65.     Child3.prototype = new Person("CaoCao");  
  66.     Child3.prototype.slim = function()  
  67.     {  
  68.         alert("I am slim one");  
  69.     }   
  70.       
  71.     function test(str)  
  72.     {  
  73.         //'this' is key, it points the object where the username should belongs  
  74.         document.writeln(this.username + " " + str);  
  75.     }  
  76.       
  77.     var p1 = new Person("lisi");  
  78.       
  79.     p1.getInfo();  
  80.       
  81.     var woman = new women("beauty",29);  
  82.     alert(woman.username);  
  83.     woman.sexy();  
  84.     //the following 2 lines contains error  
  85.     //woman.getInfo();  
  86.     //woman.pizza();  
  87.     woman.sayWorld();  
  88.       
  89.     //p1 and woman link to this in function test()  
  90.     test.call(p1,"F_CK");  
  91.     test.call(woman,"Do you still love me?");  
  92.       
  93.     var child1 = new Child("tian",3);  
  94.     child1.sexy();  
  95.       
  96.     var child2 = new Child2("tian",3);  
  97.     child1.sexy();  
  98.       
  99.     var child3 = new Child3();  
  100.     child3.sexy();  
  101.     child3.slim();  
  102.     child3.getInfo();  
  103.       
  104.