const personFactory = (setup) => { let person = { who: { // name: '', // surname: '', // age: 0, // job: 'unpemployed' }, init: function (json) { // this.who.name = json.name; // this.who.surname = json.surname; // this.who.job = json.job; // this.who.age = json.age; this.who = json; return this; }, whoami: function() { let who = this.who; return `${who.name} ${who.surname}, ${who.job}, ${who.age} years old`; }, setJob: function (job) { this.who.job = job; return this; }, grow: function(years) { if (years == null) this.who.age++; else this.who.age += years; return this; } } return person.init(setup) } geo = personFactory({ name: 'George', surname: 'Xalkis', age: 56 }) console.log('@@init', geo.whoami()); geo.setJob('developer').grow(4); console.log(geo.whoami());