Prototype
How to use getter to access private functions.
by isogunro
JavaScript
function Vehicle(theYear, theMake, theModel) {
var year = theYear;
var make = theMake;
var model = theModel;
this.getYear = function() {return year;};
this.getMake = function() {return make;};
this.getModel = function() {return model;};
}
Vehicle.prototype.getInfo = function() {
return 'Vehicle: '+ this.getYear() + ' '+ this.getMake() + ' ' +this.getModel();
}
var myCar = new Vehicle(1973, 'Mitsubishi', 'Galant');
alert(myCar.getInfo());
var herCar = new Vehicle(1985, 'Subaru', 'something');
alert(herCar.getInfo());