<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
</body>
</html>
<script>
function Animal(name){
this.type="animal"
this.name=name
this.a=[1,2]
this.sleep=function(){
console.log(this.name+"在睡觉");
}
}
function Animal2(name){
this.name=name
this.play=function(){
console.log(this.name+"正在玩");
}
}
Animal.prototype.age=5
Animal.prototype.eat=function(food){
console.log(this.name+"正在吃"+food);
}
function cat(name){
//构造继承
Animal.call(this)
Animal2.call(this)
this.name=name
}
const a=new cat("z")
a.sleep()
a.play()
console.log(a.a);
console.log(a.age);
</script>
优点