--- title: Proxy.revocable() slug: Web/JavaScript/Reference/Global_Objects/Proxy/revocable translation_of: Web/JavaScript/Reference/Global_Objects/Proxy/revocable original_slug: Web/JavaScript/Reference/Global_Objects/Proxy/revocabile ---
Il metodo Proxy.revocable()
è usato per creare un oggetto {{jsxref("Proxy")}} revocabile.
Proxy.revocable(target, handler);
Un nuovo oggetto Proxy
revocabile.
Un Proxy
revocabile è un oggetto con le seguenti due proprietà {proxy: proxy, revoke: revoke}
.
proxy
new Proxy(target, handler)
.revoke
proxy
.Se la funzione revoke()
viene invocata, il proxy diventa inutilizzabile: se si tenta di farne uso si otterrà un {{jsxref("TypeError")}}. Una volta che il proxy è revocato rimarrà in questo stato e potrà essere eliminato dal garbage collector. Successive invocazioni di revoke()
non avranno effetto.
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); // viene sollevato un TypeError proxy.foo = 1 // viene sollevato un TypeError delete proxy.foo; // viene sollevato un TypeError typeof proxy // "object", typeof non innesca nessuna trappola
Specification | Status | Comment |
---|---|---|
{{SpecName('ES2015', '#sec-proxy.revocable', 'Proxy Revocation Functions')}} | {{Spec2('ES2015')}} | Definizione iniziale. |
{{SpecName('ESDraft', '#sec-proxy.revocable', 'Proxy Revocation Functions')}} | {{Spec2('ESDraft')}} |
{{Compat("javascript.builtins.Proxy.revocable")}}