Is this a good way to make a private property in JavaScript production code? It should be equivalent of "private" in Java because objects which inherit from below should not have access to foo and boo. How to make method or property "protected"?
var Constructor = function(val) {
var foo = val //private property
var boo = function() {} //private method
this.getFoo = function() {
return foo
}
};
var obj = new Constructor(1)
var obj2 = new Constructor(2)
console.log(obj.getFoo())
console.log(obj2.getFoo())
Regards