The Proxy.revocable()
method is used to create a revocable Proxy
object.
Proxy.revocable(target, handler);
target
Proxy
. It can be any sort of object, including a native array, a function, or even another proxy.handler
p
when an operation is performed on it.A newly created revocable Proxy
object is returned.
A revocable Proxy
is an object with following two properties {proxy: proxy, revoke: revoke}
.
proxy
new Proxy(target, handler)
call.revoke
proxy
.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 |
---|
ECMAScript (ECMA-262) The definition of 'Proxy Revocation Functions' in that specification. |
Desktop | ||||||
---|---|---|---|---|---|---|
revocable |
63 | 12 | 34 | No | 50 | 10 |
Mobile | ||||||
---|---|---|---|---|---|---|
revocable |
63 | 63 | 34 | 46 | 10 | 8.0 |
Server | |
---|---|
revocable |
6.0.0 |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://wiki.developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/revocable