<script>
//动物类
var animal = function(name, age) {
this.age = age;
this.name = name;
};
//动物的原型
animal.prototype = {
getName() {
return this.name;
},
getAge() {
return this.age;
}
};
//人类
var person = function(name, age, haoma) {
animal.call(this, name, age);
this.haoma = haoma;
};
//人的原型
Object.assign(person.prototype, animal.prototype, {
getHaoMa() {
return this.haoma;
}
});
var per01 = new person("xux", 39, 12123)
console.log(per01.getName(), per01.getAge(), per01.getHaoMa());
var per02 = new person("aitao", 93, 1753)
console.log(per02.getName(), per02.getAge(), per02.getHaoMa());
</script>
打印结果:
FR:徐海涛(hunk Xu)
QQ技术交流群:386476712