You probably use meta programming everyday without even realizing it, so let’s take a brief few moments to discover the basic concepts behind the world of metaprogramming. Metaprogramming is is all about what’s under the hood, as opposed to the higher levels of programming like business logic or data modelling. Metaprogramming can be described as “making programs making programs” or something similar.
Imagine a guy who builds cars. Say it’s the same thing as using a computer. At some point he realizes he’s always doing the same thing, more or less. So he builds factories to build cars, and it’s much better. He’s now programming! Nevertheless, once again, at some point, he realizes he’s always doing the same thing, to some extent. Now he decides to build factories that build factories that build cars.
One feature of metaprogramming is code generation, like for example
Also, all of the available methods on Object are Reflection,
Object.getOwnProperties. Let me remind you that Reflection tools that don’t alter code, but instead gather information are often called Introspection). Also we have Reflection/Introspection operators, like
So without further ado, the new APIs in ES6 come in three:
Proxy. Symbols are all about Reflection within implementation - you dabble them on your existing classes and objects to change the behavior. Reflect is all about Reflection through introspection which is used to discover very low level information about your code. Proxy is all about Reflection through intercession and wrapping objects & intercepting their behaviours through traps.