javascript继承--原型链继承

 1 <script language="javascript" type="text/javascript">
2 function Parent(){
3 }
4 function Child(){
5 }
6
7 Parent.prototype.name="小张";
8 Parent.prototype.sayHello=function (){
9 alert(this.name);
10 }
11 Child.prototype=Parent.prototype; /*等价于Child.prototype=new Parent();*/
12
13 var ch=new Child();
14
15 ch.sayHello();
16 </script>
posted @ 2012-04-08 18:44  unbreakable  阅读(154)  评论(0编辑  收藏  举报