Wrapping Up
Metaprogramming is an advanced concept that provides the ability to extend a program at runtime. It is used extensively by libraries and frameworks, but you can also cautiously use it to extend third-party classes in order to make code fluent, less noisy, and easier to use. Member injection is useful to add a known method, field, or property into a class without inheriting from it. To add a method to a class, inject it into the class’s prototype. To inject properties, use the defineProperty() or defineProperties() method.
Exercises
The following exercises will help you strengthen your metaprogramming skills to query objects and inject members. You can find answers to these exerciseshere.
Exercise 1
Complete the following code to print ...
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