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>