April 2018
Intermediate to advanced
284 pages
5h 46m
English
| Tip 40 | Simplify Interfaces with get and set |
In this tip, you’ll learn how to mask logic behind simple interfaces with get and set.
You have the basics of classes. You can create instances, call properties, call methods, and extend parent classes. But it won’t be long before someone tries to alter a property you had no intention of exposing. Or maybe someone sets the wrong data type on a property, creating bugs because the code expects an integer, not a string.
One of the major problems in JavaScript is that there are no private properties by default. Everything is exposed. You can’t control what the users of your class do with the methods or properties.
Think about your Coupon. It has a property of price, which you initially set in the constructor. ...
Read now
Unlock full access