Js建立對象

Js建立對象與構造函數的繼承關係javascript

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4 <meta charset="UTF-8">
 5 <title>Insert title here</title>
 6 <script type="text/javascript">
 7     window.onload = function(){
 8         function Super(){
 9             this.s='歲';
10             this.f=function(){
11                 return '歲';
12             }
13         }
14         function Person() {
15             Super.call(this)
16             this.name='張三';
17             this.chinese='98';
18             this.math='80';
19         }
20         function Student(){
21             Person.call(this);
22             this.age=25;
23             this.info=function(){
24                 return '姓名:'+this.name+'<br>語文:'+this.chinese+'<br>數學:'+this.math+'<br>年齡:'+this.age+this.f()
25             }
26         }
27         document.getElementById('info').innerHTML=new Student().info();
28     }
29 </script>
30 </head>
31 <body>
32     <p id="info"></p>
33 </body>
34 </html>
相關文章
相關標籤/搜索