security issues : factory function
JavaScript
function User() {
var authorized = false;
function isAuthorized(){
return authorized;
}
return Object.freeze({
isAuthorized
});
}
const user = User();
user.authorized = true; //access to private property
user.isAuthorized = function() { return true; } //redefine the public API
console.log(user.isAuthorized()); //false