方法一:借助構造函數實現繼承
這種方法的缺點:原型鏈上的東西並沒有被繼承。
方法二:借助原型鏈實現繼承
這種方法的缺點:改變了一個實例對象,另一個實例對象也跟着改變,因為s1.__proto__ === s2.__proto__。
方法三:組合方式
這種方法的缺點:父類的構造方法執行了2次,分別在Parent3.call(this)和Child3.prototype = new Parent3()。
方法四:組合方式的優化1
這種方法的缺點:無法區分實例是由誰創建的,console.log(s5.constructor)輸出為Parent4,但實際上s5是由Child4創建的。
方法五:組合方式的優化2
console.log(s7 instanceof Child5,s7 instanceof Parent5);輸出true,true。
console.log(s7.constructor);輸出為Child5。所以,第五種是比較完美的方法。