JavaScript之构造函数

[javascript] 
 
  1. <html>  
  2. <head>  
  3. <mce:script type="text/javascript"><!--  
  4.     function CTest(width, height)  
  5.     {  
  6.         this.m_nWidth=width;  
  7.         this.m_nHeight=height;  
  8.     }  
  9.     CTest.prototype=  
  10.     {  
  11.         m_nWidth: 0,  
  12.         m_nHeight: 0,  
  13.           
  14.         m_pfnPrintInfo: function()  
  15.         {  
  16.             var strInfo = "";  
  17.             strInfo += "width = " + this.m_nWidth + "/theight = " + this.m_nHeight + "\n";  
  18.               
  19.             alert(strInfo);  
  20.         }  
  21.     };  
  22.       
  23.     var objT1 = new CTest(1, 2);  
  24.     var objT2 = new CTest(12.3, 45.6);  
  25.       
  26.     objT1.m_pfnPrintInfo();  
  27.     objT2.m_pfnPrintInfo();   
  28.       
  29. // --></mce:script>  
  30. </head>  
  31. <body onload="">  
  32.     <h1><font color="#ff0000">Test for new Object </font></h1>  
  33. </body>  
  34. </html>  

 摘自:http://blog.csdn.net/andylin02/article/details/4297681

原文地址:https://www.cnblogs.com/ghw0501/p/4733884.html