JS
See the Pen thecodelog.com - ES6 Proxies 1 by Deano (@deangilewicz) on CodePen.
The proxy becomes the primary object the code interfaces with, and the actual target object remains hidden/protected. You might do this because you want to pass the object somewhere that can’t be fully “trusted” and so you need to enforce special rules around its access rather than passing the object itself.
A regular proxy always traps for the target object, and cannot be modified after creation.
See the Pen thecodelog.com - ES6 Proxies 2 by Deano (@deangilewicz) on CodePen.
Each available proxy trap has a corresponding Reflect static function of the same name. Reflect is an object but does not have a constructor. You will more than likely use both Proxy and Reflect in tandem.
It is possible to revoke a Proxy by calling Proxy.revocable(). This expects 2 params: a Proxy object, and a revoke function that accepts no arguments. If the revoke() function gets called, the proxy becomes unusable: Any trap to a handler will throw a TypeError. Once a proxy is revoked, it will remain revoked and can be garbage collected. Calling revoke() again has no effect.
See the Pen thecodelog.com - ES6 Proxies 3 by Deano (@deangilewicz) on CodePen.