The idea of metaprogramming
According to the definition of free encyclopedia (http://www.wikipedia.org): write some programs to generate some data or code in advance for runtime use, the program used to generate the data information or code is called metaprogram ).
Metaprogramming is widely used in computer programming. If you have a large application with many functions including the same code, you can create a small program (such as a macro definition in C ), use it to generate these code with common functions, and spend more time to implement the important part.
Metaprogramming has many practical methods, but its core idea remains unchanged: To construct new programs with programs. It seems very advanced to construct a new program. Otherwise, the construction of a new program here only indicates that the program has new functions through a certain logical relationship.
In JavaScript, for a function, the JavaScript engine can execute it as a method and construct it as an object type. However, they are different. They have different roles in addition to their forms. The main difference is: as a function, it can be executed directly and fully utilize the context of the Function Code body, such as being convenient by applying or calling methods; being used as a constructor is greatly restricted and lacks the flexibility of functions.
In JavaScript, metaprogramming is implemented. The so-called metaprogram is function, and the data or code used for running is a series of extensions derived from function or function.
This article is recommended by Tu chuanbin and Yang xianting, author of "conquer Ria: javascript-based Web Client development ".