混入式继承
var person1 = {
house: {
address: '东京',
price: 1000k
},
car: {
brand: '保时捷911',
price: 1000k
}
}
var person2 = {
girlFriend: ['菜菜子','南小鸟','狂三']
}
for (var key in person1) {
person2[key] = person1[key]
}
console.log(person2)
原型替换继承
var person1 = {
house: {
address: '旧金山',
price: '2000k'
},
car:{
brand: '比亚迪宋max',
price: '2000k'
}
}
function Rich_person(gfs) {
this.gfs = gfs
}
Rich_person.prototype.plane = {
price: '30000k',
kind: 'airBus'
}
var p2 = new Rich_person(['十香','奈亚子'])
console.log(p2)
Rich_person.prototype = person1
var p3 = new Rich_person(['四系乃','康娜'])
console.log(p3)
混合式
var person1 = {
house: {
address: '旧金山',
price: '2000k'
},
car:{
brand: '比亚迪宋max',
price: '2000k'
}
}
function Rich_person(gfs) {
this.gfs = gfs
}
Rich_person.prototype.plane = {
price: '30000k',
kind: 'airBus'
}
var p2 = new Rich_person(['十香','奈亚子'])
console.log(p2)
for (var key in person1) {
Rich_person.prototype[key] = person1[key]
}
console.log(p2)