Today a small reflection about the object reflection. I’ll try to be concise.
Reflection of objects is not just a curiosity, but also a tool, which we can meet more often than we think. And it may turn out to be this, what we need when we stuck with some issue.
The reflection mechanism allows us to work with the code in the same way, as with the data.
This means that we can operate on the code as on the data, and create our own structures modifying the standard operation of the language.
Reflection is usually encountered in high-level languages, most often based on a virtual machine. Such techniques are probably well known by developers of languages such as Python or Ruby.
The main thing in this case is an overview of the elements, on which our object is built. And this is what we will do now.
Viewing object components
This is possible through the Object.getOwnPropertyNames method.
Example — Math object:
The result will be similar to following:
With just one line of code we received really valuable information that can be further processed.