<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>类式继承模式#3——借用和设置原型</title> </head> <body> <script type="text/javascript"> function Parent(name){ this.name=name||'Adam'; }; Parent.prototype.say=function(){ console.log(this.name); }; function Child(name){ Parent.apply(this,arguments); }; Child.prototype=new Parent(); /***************************************/ var kid=new Child('Janking'); console.log(kid.name); kid.say(); //缺点:父构造函数被调用了两次,因此导致了其效率低下的问题,最后,自身的属性会被继承两次。 </script> </body> </html>