concept encapsulation in category javascript

appears as: encapsulation
The Joy of JavaScript

This is an excerpt from Manning's book The Joy of JavaScript.

Never reveals any unnecessary details about the shape of the object or any operations that might take place during instantiation—encapsulation is always a good choice. Whereas, if you expect your users to use objects as is:

const transaction = {
   sender: 'luis@joj.com',
   recipient: 'luke@joj.com'
}

Now you’ve handcuffed yourself from making any modifications by violating encapsulation. This is a fundamental design decision of any object-oriented system to make your code less fragile and more maintainable. Once clients of your API start to use this in production, you’re locked into supporting this object for the lifetime of your API and making changes to it should be done rather carefully in order to reduce the risk of breaking anyone else’s code.