A revocable proxy is a proxy that can be revoked (that is, switched off).
To create revocable proxies we have to use the Proxy.revocable() method. The Proxy.revocable() method is not a constructor. This method also takes the same arguments as the Proxy constructor, but, instead of returning a revocable proxy instance directly, it returns an object with two properties, which are the following:
- proxy: This is the revocable proxy object
- revoke: When this function is called, it revokes the proxy
Once a revocable proxy is revoked, any attempts to use it will throw a TypeError exception. Here is an example to demonstrate how to create a revocable proxy and revoke it:
const revocableProxy = Proxy.revocable({ ...