轉自神三元的博客,這段代碼真的很美
組合繼承(簡直完美)
function Parent5 () {
this.name = 'parent5';
this.play = [1, 2, 3];
}
function Child5() {
Parent5.call(this); //使用call改變作用域
this.type = 'child5';
}
Child5.prototype = Object.create(Parent5.prototype); //集成原型上的屬性和方法
Child5.prototype.constructor = Child5; //集成直接對象上的屬性和方法