If you want the prototype definition of inner nested classes not to be accessible from outside the outer class, as well as a simpler OO implementation, take a look at this.
var BobsGarage = BobsGarage || {};
BobsGarage.Car = function() {
var Engine = function() {
};
Engine.prototype.constructor = Engine;
Engine.prototype.start = function() {
console.log('start engine');
};
var Tank = function() {
};
Tank.prototype.constructor = Tank;
Tank.prototype.fill = function() {
console.log('fill tank');
};
this.engine = new Engine();
this.tank = new Tank();
};
BobsGarage.Car.prototype.constructor = BobsGarage.Car;
BobsGarage.Ferrari = function() {
BobsGarage.Car.call(this);
};
BobsGarage.Ferrari.prototype = Object.create(BobsGarage.Car.prototype);
BobsGarage.Ferrari.prototype.constructor = BobsGarage.Ferrari;
BobsGarage.Ferrari.prototype.speedUp = function() {
console.log('speed up');
};
var car = new BobsGarage.Car();
car.tank.fill();
car.engine.start();
var ferrari = new BobsGarage.Ferrari();
ferrari.tank.fill();
ferrari.engine.start();
ferrari.speedUp();
console.log(ferrari);
, , , BobsGarage.Car, BobsGarage.Car, , .
. Javascript, MDN.