Metaprogramming in JavaScript
Introduction to “reflect-metadata” package and its ECMAScript proposal
In this lesson, we are going to take a look at the reflect-metadata
package used by TypeScript to design decorators. This package is primarily used as a polyfill for the Reflect
API’s “metadata-extension” ECMAScript proposal.
Metadata, in a nutshell, is extra information about the actual data. For example, if a variable represents an array, the length of that array is metadata. Similarly, each element in that array is data but the data-type of these elements is metadata. Loosely speaking, metadata is not the actual concern of a program, but it can help us achieve things quicker.
Let’s take a small example. If you need to design a function that prints information about other functions, what information would you print?
In the above example, the funcInfo
function takes a function as an argument and returns a string that contains function name and the number of arguments this function…