JavaScript에서이 유형의 상속이 작동하지 않는 이유는 무엇입니까? 이 단계를 수행 할 수있는 방법이 있습니까? 내가 좋은 생각되지 않습니다 Function
프로토 타입을 확장 한JavaScript의 다중 상속
function base() {}
base.prototype.findFirst = function() {
console.log("FindMe First");
}
function base2() {}
base2.prototype.findMe = function() {
console.log("FindMe ");
}
function inherit() {
base.call(this);
base2.call(this);
}
inherit.prototype = base.prototype;
inherit.prototype.constructor = inherit;
inherit.prototype = base2.prototype;
inherit.prototype.constructor = inherit;
var test = inherit();
test.findFirst();
test.findMe();
자바 스크립트 개체에는 여러 프로토 타입 체인이있을 수 없습니다. 이것은 가능하지 않습니다. –
#doingitwrong이라고 말씀 드리고 싶습니다. JS는 객체 지향 언어가 아닌 함수형 프로그래밍 언어입니다. OOP 구현이 원하는대로 작동하지 않기 때문에 OOP 구현을 시도하는 것보다 (예 : 클로저) 사용할 수있는 강력한 기능을 사용하는 것이 더 나을 것입니다. – Joe
다중 상속은 가능한 경우 언어에서조차별로 좋은 아이디어가 아닙니다. 그리고 Javascript에서는 그렇지 않습니다. –