JavaScript, Functional Programming, Web Development, State Encapsulation, Javascript State.
alternate approach. If we simply use closures, we can define an object-creating function like this: const MyObj3 = initVal => { let myVal = initVal return { get: function() { return myVal }, set: function(val) { myVal = val } } } Just like the approach above, we can use it to create an object like