Debating the prototype/private compromise
HTML
<!--
Notes : Debating the prototype/private compromise
You’ve learned the primary patterns for creating a JavaScript object, but there can be a compromise in which you can have private data that is readable by creating a method for retrieving the data, also known as a getter, which has no setter, a method for setting the value.
** the privileged getters are small, which minimizes the amount of memory consumed when each instance has a copy of the method. Remember to create only getter methods as needed and to keep them small and concise.
-->
JavaScript
var car;
function Vehicle(year,modelname){
var model = modelname;
var modelmakeyear = year;
this.makemodel = function(){return model;};
this.makeyear = function(){return modelmakeyear;};
}
Vehicle.prototype.show = function(){
console.log(this.makemodel() + "--"+this.makeyear());
};
car = new Vehicle("BMW","2015");
car2 = new Vehicle("Mercedes","2015");
car.show();
car2.show();