<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>继承</title>
</head>
<body>
<script type="text/javascript">
/*继承:
被继承者: people 父类(基类、超类)
继承者: student 子类(派生类)
继承是单向的*/
function People(name,age){
this.name=name;
this.age=age;
}
People.prototype.say=function(){
console.log(this.name+' 在说话');
};
People.prototype.showInfo=function(){
console.log('姓名:'+this.name+',年龄:'+this.age);
};
function Student(name,age,no,grade){
People.call(this,name,age);
this.no=no;
this.grade=grade;
}
//方法的继承
for(var i in People.prototype){
Student.prototype[i]=People.prototype[i];
}
Student.prototype.test=function(){
console.log(this.name+' 在进行期末考试......');
};
var p=new People('李四',22);
p.say();
p.showInfo();
// p.test();
console.log('-------------------------------');
var s=new Student('小花',20,'1000','一年级');
s.say();
s.showInfo();
s.test();
</script>
</body>
</html>