The Proxy.revocable() method is used to create a revocable Proxy object.
Proxy.revocable(target, handler);
targetProxy.handlerA newly created revocable Proxy object is returned.
A revocable Proxy is an object with following two properties {proxy: proxy, revoke: revoke}.
proxynew Proxy(target, handler) call.revokeproxy.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.
var revocable = Proxy.revocable({}, {
get: function(target, name) {
return "[[" + name + "]]";
}
});
var proxy = revocable.proxy;
console.log(proxy.foo); // "[[foo]]"
revocable.revoke();
console.log(proxy.foo); // TypeError is thrown
proxy.foo = 1 // TypeError again
delete proxy.foo; // still TypeError
typeof proxy // "object", typeof doesn't trigger any trap
| Specification | Status | Comment |
|---|---|---|
| ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Proxy Revocation Functions' in that specification. | Standard | Initial definition. |
| ECMAScript Latest Draft (ECMA-262) The definition of 'Proxy Revocation Functions' in that specification. | Living Standard |
| Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|---|
| Basic support | Yes | Yes | 34 | No | Yes | 10 |
| Feature | Android webview | Chrome for Android | Edge mobile | Firefox for Android | IE mobile | Opera Android | iOS Safari |
|---|---|---|---|---|---|---|---|
| Basic support | Yes | Yes | Yes | 34 | No | Yes | 10 |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/revocable