function Parent(){
this.name = "Parent"
this.Arr = [1,2,3]
}
function Child(){
this.type= "Child"
}
Child.prototype = new Parent()
優(yōu)點(diǎn):
解決了借用構(gòu)造函數(shù)的缺點(diǎn)問題,可以繼承父類原型上的屬性
缺點(diǎn):
var child1 = new Child()
var child2 = new Child()
child1.Arr.push(4)
這時(shí)child2.Arr也變成了[1,2,3,4]
因?yàn)樗鼈兊脑椭赶蚴且粯?
3:組合方式繼承(即1和2的組合)
function Parent(){
this.name = "Parent"
this.Arr = [1,2,3]
}
function Child(){
Parent.call(this)
this.type= "Child"
}
Child.prototype = new Parent()
var child1= new Child()