The Proxy
object in javascript
Allows you to create a wrapper for another object, which can intercept and redefine fundamental operations for that object. The Proxy
allows you to create an object that can be used in place of the original object, which is where it gets the name “proxy”, and it may redefine fundamental Object
operations like getting, setting, and defining properties. Proxy objects are commonly used to log property accesses, validate, format, or sanitize inputs, and so on.
Proxy Arguments
Arg | Desc |
---|---|
target | the original object which you want to proxy |
handler | an object that defines which operations will be intercepted and how to redefine intercepted operations. |
Blank Example
|
|
Works same as normal bc the handler is empty.
|
|
Always returns world
|
|
We can also use the Reflect
class to use accessors from the original but add a condition that derives from that default.
No-Op Reflection
|
|
We can set up like this as well as a reactive handler for a parent object. Note that doing this does not give the proxy access to private properties, such as slots