JavaScript, Functional Programming, Web Development, State Encapsulation, Javascript State.
following should be pretty easy to understand: class MyObj1 { constructor(initVal) { this.myVal = initVal } set(x) { this.myVal = x } } Once instantiated: const x = new MyObj1(0) You can set the value of myVal with either: x.set(2) Or: x.myVal = 2 Similarly, you can access the field directly: