1 <script type="text/java script">
2 function classA(str){
3 this.str=str;
4 this.printstr=function(){
5 document.write(this.str);
6 document.write("<br>");
7 }
8 this.getstr=function(){
9 return this.str;
10 }
11 }
12 function classB(name,str){
13 //利用call方法实现继承
14 classA.call(this,str);
15 this.name=name;
16 this.sayName=function(){
17 document.write(this.name);
18 document.write("<br>");
19 }
20
21 }
22 var a=new classB("Amy","helloworld");
23 a.printstr();
24 alert(a.getstr());
25 a.sayName();
26 </script>