javascript中类的继承
点击次数:43 次 发布日期:2008-11-06 07:53:12 作者:源代码网
|
源代码网整理以下<html xmlns="http://www.w3.org/1999/xhtml" > { SayYes(words); document.write("ID: "+this.ID+"|Name: "+this.Name+"<br />"); } } Movie.prototype.SayHello=function(words) { alert(words); } function Animal(sex,age)//基类 { this.Sex=sex; this.Age=age; } function People(id,name,sex,age)//子类 { //People.prototype=new Animal(); this.ID=id; this.Name=name; this.Sex=sex; this.Age=age; this.Say=function() { document.write("ID:"+this.ID+"|Name:"+this.Name+"|Sex:"+this.Sex+"|Age:"+this.Age); } } People.prototype=new Animal(); </script> </head> <body> <form id="form1" runat="server"> <div> <script type="text/javascript"> var a=new Movie(1,"abc",10); a.ShowInfo("Yes"); a.SayHello("Hello"); var b=new People(1,"a","男",10); b.Say(); </script> </div> </form> </body> </html> 源代码网推荐 源代码网供稿. |
