Metaprogramming refers to the "programming the language itself" by developers ". Generally, the programming language exposes some APIs for developers to operate on certain features of the language. Starting from ES6, the Proxy and Reflect features have been added, and meta programming has been extended (MetaPro... meta programming refers to developers programming the language itself ". Generally, the programming language exposes some APIs for developers to operate on certain features of the language.
Starting from ES6, the Proxy and Reflect features have been added, and Meta Programming capabilities have been extended to intercept and customize basic language operation behaviors (such as attribute search, assignment, enumeration, function call ).
Proxy)
Proxy is a new feature added to ES6. it can "Proxy" the native behavior of the object and replace it with the execution of custom behavior.
Proxy can be understood as setting up a "blocking" layer before the target object. the external access to this object must first intercept through this layer. Therefore, a mechanism is provided, attackers can filter and rewrite external accesses. The original intention of the word "Proxy" is "Proxy", which indicates that it is used to "Proxy" some operations and can be translated as "Proxy ".
Proxy objects are used to define user-defined behaviors for basic operations (such as property search, assignment, enumeration, and method calls.
Create a Proxy object:
In the above code, each Proxy object's interception operations (get, delete, has) call the corresponding Reflect method internally to ensure that Native behavior can be executed normally. The ADD operation outputs a log line for each operation. With the Reflect object, many operations will be easier to read.
The above is a detailed description of ES6's new feature development applet (6). For more information, see other related articles in the first PHP community!