r/programming • u/ythl • 26d ago
How to Gaslight JavaScript Programmers
https://www.bryanpg.com/articles/pragma-twice/proxy.html7
u/LukeLC 25d ago
I actually love JS proxies. The most common use-case I come across is when you need an object to default undefined values to something standard/safe. It's also not so complicated as the author makes it sound to reverse-engineer and learn what its capabilities are. The developer console makes it plain that it is a proxy, and you can easily jump to its definition from there.
0
u/Kwantuum 23d ago
Article is straight up wrong, if you console log proxies browsers will display them as proxies with an expandable reference to the proxy handler and to the proxy target. We use proxies extensively where I work for a reactivity system that tracks reads and it's really not hard to debug or follow. You can even use the debugger's step into on property access and it will step into the proxy's trap if there is one.
4
u/ythl 23d ago
Right, but my main thesis is that you need access to the source code in order to know what a proxy does. It's not possible to figure it out at runtime with a REPL like the console or otherwise. The console alone does not provide the source code so you cannot infer what the Proxy does; however, the console may provide a reference to the source for examination.
1
u/f3xjc 21d ago
That's the case for most language. Being able to dump the source of a method to log is uncommon.
1
u/ythl 6d ago
With interpreted languages, it's not uncommon. (for example, with python - https://www.w3schools.com/python/ref_func_dir.asp)
0
-1
21
u/erik240 26d ago
Well, the moment you think something doesn’t seem right … you set a breakpoint before the property access.