ES6 (Proxy and Reflect)

Proxy and Reflect

1. The concept of Proxy and Reflect

Proxy means 'proxy' and connects a layer between the user and the real object

Reflect means 'reflection', reflecting the Object

2. Applicable scenarios

 

1. Proxy syntax

1. Similar to the original object obj of the supplier, a new object is generated through the Proxy. This object is mapped to the Object, and the user accesses the monitor,

Through Proxy, and then passed to the obj object.

2. Set the simplest proxy operation (intercept read function)

The real one is 2017-03-11, through the role of 'proxy', replace 2017 with 2018.

 3. Set properties

Only the name attribute can be modified (target is the object to be modified, key is the attribute to be modified, and value is the value to be modified)

At this point the name value has changed

4. Determine whether the current object has a certain attribute

Only check if the name attribute exists

5. Delete

Remove if attribute starts with '_'

 6. Traverse

(protect the time attribute)

2. Reflect syntax

1. Read object properties

set

 

has

 

3. Practical application

 1. Determine whether the format is correct (check)

 

Filter (check) conditions

object

output result

 

Some properties are modified

The reason for the error is because the return object of the final constructor is not this, but a proxy for this

This is the role of Proxy proxy, the advantage is to isolate conditions and objects, which is conducive to post-code maintenance

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325069595&siteId=291194637