In the previous recipe, we saw how to prevent values from being written. Sometimes however, we don't want to prevent a property from being written to. Rather, we want to control how it is written to. In this recipe, we'll see how to use set to control the writing of a property.
Using setters to encapsulate values
Get ECMAScript Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.