function Car(name) {
this.name = name;
this.speed = 100;
this.engine = "V6";
}
Car.prototype.rides = function() {
alert(this.name +' '+ this.engine + " едет!")
}
Car.prototype.ridesspeed = function() {
alert(this.speed + " км в час скорость "+this.name +' '+ this.engine)
}
function SportCar(name) {
this.model = "M3";
this.speedsp = 200;
this.enginesp = "V10";
Car.apply(this, arguments);
}
SportCar.prototype = Object.create(Car.prototype);
SportCar.prototype.constructor = SportCar;
SportCar.prototype.rides = function() {
Car.prototype.rides.apply(this);
alert( this.name +' '+ this.model +' '+ this.enginesp + " дрифтует!" );
};
SportCar.prototype.ridesspeedsport = function() {
alert(this.speedsp + " км в час скорость " + this.name +' '+ this.model +' '+ this.enginesp)
}
var sportcar = new SportCar('BMW');
sportcar.rides();
sportcar.ridesspeed();
sportcar.ridesspeedsport();
function SportCar(name) {
Car.apply(this, arguments);
this.model = "M3";
this.speedsp = 200;
this.enginesp = "V10";
}
// Общие св-ва и методы для всех машин сюда
var car = {
rides: function() {
alert( this.name + ' ' + this.engine + ' едет!')
},
ridesSpeed: function() {
alert( this.speed + ' км в час скорость ' + this.name + ' ' + this.engine )
}
};
// Только для спортивных сюда
function SportCar( name, speed, engine ) {
this.__proto__ = car;
this.name = name;
this.speed = speed;
this.engine = engine;
}
var bmw = new SportCar( 'BMW', 200, 'v6' );