June 2018
Beginner
288 pages
6h 31m
English
In an earlier example, in Injecting Multiple Properties, we introduced a few missing properties like first and last into arrays. That’s member injection—we knew what to introduce or inject at code writing time. While that’s fun and useful, member synthesis ups the challenge and the resulting benefits by a few notches. With synthesis we can bring on board new members into a class based on runtime context. We can also alter the behavior of existing methods or properties dynamically based on the current state at runtime. To achieve this, we need the help of the Proxy class. We’ll first explore this newly added class in JavaScript and then employ it for method synthesis.
An instance of the Proxy class ...