Decorating (your Javascript) for Fun and Profit

Sometimes you need to get “meta”. What if you could tell a variable that any time it changes, it should automatically report that change to a log file, without you having to write code to do it? What about identifying a function should be called by a web server whenever a particular URL pattern is matched? Or maybe, as with tools like mobX, you want to have functions be invoked only when the variables they reference change. These could radically simplify the amount of “communication” code that you need to write, and more can concentrate the responses to such changes in a consistent manner rather than force piecemeal edits. This is the role of decorators, perhaps one of the most important capabilities to emerge from the ES2017 upgrades. This post will give a quick primer on ES2017 Decorators.

Kurt Cagle
Kurt Cagle ( is an author of twenty books, blogger, and software architect, and is available for consulting or hire. He lives in Issaquah, WA with his wife, daughters, and cat.