I have seen several ways to do inheritance in javascript, but I do not know how to do multiple-inheritance
function Transporte() {
var nome;
this.getNome = function () {
return nome;
};
this.setNome = function (value) {
nome = value;
};
}
function Motor() {
var motor;
this.getMotor = function () { return motor; };
this.setMotor = function (value) { motor = value; };
}
function Propulsor() {
var propulsor;
this.getTurbina = function () { return propulsor; };
this.setTurbina = function (value) { propulsor = value; };
}
Motor.prototype = new Transporte();
Propulsor.prototype = new Transporte();
function document_OnLoad() {
var carro = new Motor();
var aviao = new Propulsor();
carro.setMotor('4.1');
carro.setNome('opala');
aviao.setTurbina('123');
aviao.setNome('Teco-Teco');
console.log(carro.getMotor()+' '+carro.getNome());
console.log(aviao.getTurbina()+' '+aviao.getNome());
}
In this way the source code was written, I have a simple inheritance:
- Car Instance Engine and inherit Transport
- Plane Instance Propeller and inherit from Transport
My question is:
How to use prototype to inherit Engine, Propeller and Transport?
Can you use some feature to inherit Engine, Propeller and Transport?