面向对象组合继承
function Person(name,sex,age){
this.name = name;
this.sex = sex;
this.age = age;
}
Person.prototype.eat = function(){
console.log("每個人都會吃飯");
}
function Programmer(name,sex,age){
this.habby = "看書";
Person.call(this,name,sex,age)
}
Programmer.prototype = Person.prototype;
Programmer.prototype.writeCode = function(){
console.log("寫代碼");
}
var programmer = new Programmer("張三","男",20);
console.log(programmer);
this.name = name;
this.sex = sex;
this.age = age;
}
Person.prototype.eat = function(){
console.log("每個人都會吃飯");
}
function Programmer(name,sex,age){
this.habby = "看書";
Person.call(this,name,sex,age)
}
Programmer.prototype = Person.prototype;
Programmer.prototype.writeCode = function(){
console.log("寫代碼");
}
var programmer = new Programmer("張三","男",20);
console.log(programmer);
轉載于:https://www.cnblogs.com/songxiaopei/p/5920923.html
總結
- 上一篇: 梦到河里抓鱼是什么意思
- 下一篇: 梦到死人发丧有什么兆头