I have very quickly mocked this up as an example model in Angular JS:
.factory('car', function() {
function car(serial, name, type, manufacturer)
//intended to be private
var serial = serial;
var name = name;
var type = type;
var manufacturer = manufacturer;
this.getSerial = function() {
return this.serial;
}
this.setSerial = function(newSerial) {
this.serial = newSerial;
}
});
There would be getters and setters for every property, and there is a legitimate need for getters and setters for all of them.
I am not a hardcore JavaScript developer, but I have been reading that providing getters and setters for every property is bad practice and providing them in general is bad practice.
- Let's say there is a legitimate need for getters and setters for all of the properties, is it still bad practice?
- Would other developers do it another way? I have also seen developers writing about it doing in completely different ways
I am after encapsulation of these properties and I assume that this is a good way to go about it.