1. 程式人生 > >面向對象繼承相關

面向對象繼承相關

上下 parent 構造 prototype 父類構造函數 實現繼承 his pro UNC

實現繼承的幾種方式

//構造函數繼承

//在子構造函數中執行父類構造函數,改變父類構造函數this指向,使父類屬性掛載到子類上

//缺點不能繼承Parent11.prototype上的屬性和方法,只能繼承構造函數內的屬性方法

function Parent1(){
this.name=‘Parent1‘
}
function Child1(){
Parent1.call(this) //apply 改變函數運行的上下文
this.childType=‘Child1‘
}

面向對象繼承相關