<script>
//人类 父类
function Human(name,age,height){
this.name=name
this.age=age
this.height=height
}
Human.prototype.sleep=function(){
console.log(this.name+"正在睡觉")
}
Human.prototype.shopping=function(){
console.log(this.name+"正在购物")
}
Human.prototype.run=function(){
console.log(this.name+"正在奔跑")
}
//1.原型链继承
//学生类 子类
// function Student(name,age,height){
// }
// Student.prototype=new Human("小周",20,"158")
// Student.prototype.study=function(){
// console.log(this.name+"正在学习")
// }l
// Student.prototype.play=function(){
// console.log(this.name+"正在玩")
// }
// var s1=new Student()
// console.log(s1)
// console.log(s1.age)
// s1.shopping()
// //教师类 子类
// function Teacher(name,age,height){
// }
// Teacher.prototype=new Human("陆老师","42","164")
// Teacher.prototype.teach=function(){
// console.log(this.name+"正在教课")
// }
// Teacher.prototype.correct=function(){
// console.log(this.name+"正批改作业")
// }
// var t1=new Teacher()
// console.log(t1)
// console.log(t1.height)
// t1.sleep()
//2.冒充继承
//学生类
function Student(name,age,height){
Human.call(this,name,age,height)
}
Student.prototype.study=function(){
console.log(this.name+"正在学习")
}
Student.prototype.play=function(){
console.log(this.name+"正在玩")
}
var s2=new Student("小刘","21","185")
console.log(s2)
//教师类
function Teacher(name,age,height){
Human.call(this,name,age,height)
}
Teacher.prototype.teach=function(){
console.log(this.name+"正在教课")
}
Teacher.prototype.correct=function(){
console.log(this.name+"正批改作业")
}
var t2=new Teacher("王老师","32","176")
console.log(t2)
//3.混合继承
//学生类
function Student(name,age,height){
Human.call(this,name,age,height)
}
Student.prototype=new Human()
Student.prototype.study=function(){
console.log(this.name+"正在学习")
}
Student.prototype.play=function(){
console.log(this.name+"正在玩")
}
var s3=new Student("小马","16","180")
console.log(s3)
console.log(s3.name)
s3.run()
//教师类
function Teacher(name,age,height){
Human.call(this,name,age,height)
}
Teacher.prototype=new Human()
Teacher.prototype.teach=function(){
console.log(this.name+"正在教课")
}
Teacher.prototype.correct=function(){
console.log(this.name+"正批改作业")
}
var t3=new Teacher("赵老师","28","166")
console.log(t3)
console.log(t3.age)
t3.sleep()
// 1.原型链继承:
// 优点:将父类对象赋值给子类原型上,让父级对象作为子集的原型
// 缺点:所有属性相同,无法对父级属性进行初始化
// 2.冒充继承
// 优点:通过call或者apply更改对应的this指向完成继承,可以更改其this指向,指向参数对象
// 缺点:冒充继承无法继承 原型中的方法
// 2.混合继承
// 优点:通过冒充继承来继承对应属性 ,通过原型继承继承对应方法
// 缺点:无
</script>