Metaprogramming is a powerful tool in any language, and with the advent of ES6, there are even more options for metaprogramming in JavaScript now! ES6 added Reflect
and Proxy
to its repertoire of built-in objects, which allow for dynamic behavior in your code.
At its core, metaprogramming is simple—it just means programs that can write programs. Think of it as code that can change itself or other code while running.
As you could imagine, metaprogramming is very powerful, but also very dangerous.
- Changing the behavior of code you don’t control—for example, adding logging, validation, or other utility code to a third party library.