Chapter 12Deep Dive into Metaprogramming
Method synthesis is the most powerful form of metaprogramming. You can alter the API and the behavior of objects based on the runtime context and state of the objects. You can take existing classes and twist and turn them, the way it make sense to meet your needs, far beyond what was intended by the author of a class.
Method synthesis was not possible until very recently in JavaScript. All you could do in the past was method injection, which you saw in the previous chapter. With the introduction of method synthesis and two new classes—Reflect and Proxy—you can intercept method invocations right in the middle of their execution and change the fate of the calls, the way you like.
With the ability to synthesize ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access