Proxy.revocable()
method is used to create a revocable
Proxy
对象。
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)
调用。
revoke
proxy
.
若
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
| 规范 |
|---|
|
ECMAScript (ECMA-262)
The definition of 'Proxy Revocation Functions' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
revocable
|
Chrome 63 | Edge 12 | Firefox 34 | IE No | Opera 50 | Safari 10 | WebView Android 63 | Chrome Android 63 | Firefox Android 34 | Opera Android 46 | Safari iOS 10 | Samsung Internet Android 8.0 | nodejs 6.0.0 |
完整支持
不支持