Created
January 15, 2024 02:57
-
-
Save ryanmorr/a4aa5b87c32ac56f346f4c54ac5e0ab8 to your computer and use it in GitHub Desktop.
The only way to detect proxies without mutating the object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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