1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <title>類式繼承模式#1——默認模式</title> 6 </head> 7 8 <body> 9 <script type="text/javascript"> 10 11 function Parent(name){ 12 this.name=name||'Adam'; 13 }; 14 15 Parent.prototype.say=function(){ 16 return this.name; 17 }; 18 19 function Child(name){}; 20 21 inherit(Child,Parent); 22 23 function inherit(C,P){ 24 C.prototype=new P(); 25 } 26 27 /***************************************/ 28 29 var kid=new Child('Janking'); 30 31 console.log(kid.say()) 32 33 //缺點:inherit()並不支持將參數傳遞到子構造函數中,而子構造函數而後又將參數傳遞到父構造函數中。 34 35 36 </script> 37 </body> 38 </html>