This methodology reforce the security of a class
const Person = ({ name, age, job }) => {
const _name = name;
const _age = age;
let _job = job;
return {
getName: () => _name,
getAge: () => _age,
getJob: () => _job,
setJob: (newJob) => _job = newJob,
};
};
const me = Person({ name: 'Shaun', age: 25, job: 'developer' });
console.log(me.getJob());
me.setJob('senior developer');
console.log(me.getJob());
console.log(me._name);
console.log(me.name);
developer
senior developer
undefined
undefined
Sources: https://www.linkedin.com/learning/learning-functional-programming-with-javascript-es6-plus/