Proxy

Proxy.revocable

Creates a revocable Proxy object, returning both the proxy and a revoke function that disables the proxy

Syntax

JavaScript
Proxy.revocable(target, handler)

Parameters

ParameterTypeDescription
targetobjectThe target object to wrap
handlerProxyHandlerAn object with trap functions

Return Value

An object with proxy and revoke properties

Examples

Basic Usage
const target = { secret: 'data' }
const { proxy, revoke } = Proxy.revocable(target, {})
console.log(proxy.secret) // 'data'
revoke()
// proxy.secret // throws TypeError
Practical Example
function createTemporaryAccess<T extends object>(obj: T, ttlMs: number) {
  const { proxy, revoke } = Proxy.revocable(obj, {})
  setTimeout(revoke, ttlMs)
  return proxy
}
Advanced Usage
const { proxy, revoke } = Proxy.revocable({ x: 1, y: 2 }, {
  get(target, prop) {
    console.log(`Reading ${String(prop)}`)
    return Reflect.get(target, prop)
  }
})
console.log(proxy.x)
revoke()

Understanding Proxy.revocable

The Proxy.revocable method in JavaScript creates a revocable Proxy object, returning both the proxy and a revoke function that disables the proxy. It belongs to the Proxy object and is one of the most widely used methods for working with proxy values in modern JavaScript and TypeScript applications.

The method signature is Proxy.revocable(target, handler). It accepts 2 parameters: target, handler. When called, it returns an object with proxy and revoke properties. Understanding when and how to use revocable() helps you write more expressive, readable code.

Common use cases for Proxy.revocable include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like proxy-constructor, reflect-get, reflect-set, enabling you to chain operations together for complex data manipulation pipelines.

Supported in all modern browsers (Chrome 63+, Firefox 34+, Safari 10+, Edge 12+) and Node.js 6+.

Browser Compatibility

Supported in all modern browsers (Chrome 63+, Firefox 34+, Safari 10+, Edge 12+) and Node.js 6+.

Related Methods

More Proxy Methods

Other methods in the Proxy object

Related Tools

More Proxy Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.