First things first, this may be primary opinion based, so I'm looking for technical reasons and commonly accepted best practices to do one or the other thing.
If I write a "Class" and create a member of it, I can access the instance properties like this
function MyClass(){
var self = this;
self.foo = 'bar'
}
var instance = new MyClass();
instance.foo = '420';
I could, however, also create a method to set the property, so that there is no knowledge about the internal structure of the class needed
MyClass.prototype.setFoo = function(prop){
this.foo = prop;
};
Considering professional development, is there a reason to prefer one variant over the other?