摘要:
繼承 繼承是面向?qū)ο笳Z言的必備特征,即一個類能夠重用另一個類的方法和屬性。在JavaScript中繼承方式的實現(xiàn)方式主要有以下五種:對象冒充、call()、apply()、原型鏈、混合方式。 下面分別介紹。對象冒充 原理:構(gòu)造函數(shù)使用this關(guān)鍵字給所有屬性和方法賦值。因為構(gòu)造函數(shù)只是一個函數(shù),所以可以使ClassA的構(gòu)造函數(shù)成為ClassB的方法,然后調(diào)用它。ClassB就會收到ClassA的構(gòu)造函數(shù)中定義的屬性和方法。 示例:function ClassA(sColor){ this.color=sColor; this.sayColor=function(){ ... 閱讀全文
posted @ 2012-04-01 14:37
artwl
閱讀(711)
評論(0)
推薦(3)
浙公網(wǎng)安備 33010602011771號