Js创建对象
Js创建对象与构造函数的继承关系
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>