Chapter 5 Metaprogramming with JavaScript

Metaprogramming is defined on Wikipedia as:

the writing of computer programs that write or manipulate other programs (or themselves) as their data, or that do part of the work during compile time that is otherwise done at run time.

In modern scripting languages, however, metaprogramming normally involves the manipulation of the very mechanics of the language. Essentially, we’re talking about working with classes, functions, method calls, and concepts like inheritance, all from within the program itself.

Although at first this may seem like a rather academic pursuit, there’s actually a lot of utility to be gained from these techniques. The Ruby on Rails framework, for instance, owes a lot of its ...

Get The Art & Science of JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.