Build Better JavaScript Enums with Proxies
Sep 6, 2018 · 2 min read

When I need an enum object in JavaScript, I have been in the habit of using Object.freeze() to create a read-only object. While this works, and is a popular practice, frozen objects provide you only immutability.
What if you wanted to throw an exception when an unknown enum option was referenced? Every interaction with your enum is going to be reading an option from that enum. The “frozen…
