Skip to content

Instantly share code, notes, and snippets.

@ryanmorr
Created January 15, 2024 02:57
Show Gist options
  • Save ryanmorr/a4aa5b87c32ac56f346f4c54ac5e0ab8 to your computer and use it in GitHub Desktop.
Save ryanmorr/a4aa5b87c32ac56f346f4c54ac5e0ab8 to your computer and use it in GitHub Desktop.
The only way to detect proxies without mutating the object
// Courtesy of: https://www.reddit.com/r/javascript/comments/4wrdxd/comment/d69j04s/
const proxies = new WeakSet();
function createProxy(target, handler) {
const proxy = new Proxy(target, handler);
proxies.add(proxy);
return proxy;
}
function isProxy(obj) {
return proxies.has(obj);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment