console.log('练习继承')
function Animal(name, weight) {
this.name = name,
this.weight = weight
}
Animal.prototype.eat = function() {
return "吃东西"
}
function Dog(color) {
this.color = color
}
Dog.prototype = new Animal("二哈", "50kg")
Dog.prototype.bite = function () {
return "咬东西"
}
function Erha(sex) {
this.sex = sex
}
Erha.prototype = new Dog("黑色")
Erha.prototype.happy = function () {
return "逗主人开心"
}
var erha = new Erha("公狗")
console.log(erha.name)
console.log(erha.color)
console.log(erha.bite())
JavaScript 之 继承学习
最新推荐文章于 2021-10-05 21:36:21 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)