수 없습니다. 사실, 많은 언어가 다중 상속을 지원하지 않습니다.
당신이 거기 Plant
의 인스턴스에 Fruit
의 prototype
을 설정 한 다음 anotherPlant
의 인스턴스를 덮어 쓰기됩니다하고있는 모든. 그것은 간단하게 동일합니다;
Fruit.prototype = new anotherPlant();
그러나, 자바 스크립트가 상속 체인을 가지고 잊지 마세요. 위의 경우를 사용하여 anotherPlant
이 프로토 타입으로 Plant
인 경우 두 객체를 모두 상속받습니다.
function Plant() {
}
Plant.prototype.foo = 'foo';
Plant.prototype.baz = 'baz-a';
function AnotherPlant() {
}
AnotherPlant.prototype = new Plant();
AnotherPlant.prototype.bar = 'bar';
AnotherPlant.prototype.baz = 'baz-b';
var a = new AnotherPlant();
console.log(a.foo); // foo
console.log(a.bar); // bar
console.log(a.baz); // baz-b
JavaScript는 다른 언어와 다른 방식으로 상속합니다. 프로토 타입 상속을 사용합니다. 즉, 인스턴스를 만드는 데 사용 된 생성자 함수 prototype
속성을 따라 언어가 함수의 상속 체인 (클래스)을 결정한다는 것을 의미합니다.
이것을 확인하십시오. http://stackoverflow.com/questions/9163341/multiple-inheritance-prototypes-in-javascript – PSL