3 ms·
Proxies exist pretty much for one purpose and one purpose only: to implement membranes, like described in <https://github.com/ajvincent/es-membrane/ https://git
by pwdisswordfishc 3y ago
Proxies exist pretty much for one purpose and one purpose only: to implement membranes, like described in <https://github.com/ajvincent/es-membrane/ https://github.com/ajvincent/es-membrane/>, where you build on demand a whole parallel universe of proxies that stand in for objects existing somewhere else, and have wrapper functions convert between those proxies and real objects. Any other use is incidental and unsupported.
Admittedly, not many people know this, so those who are not deeply familiar with TC39 proceedings commonly think of proxies as just a way to hook into arbitrary behaviours of a single object, like property accesses, then are treated to a bitter surprise when proxies don’t work like what they thought or wanted.
Still, the opening example is simply a misuse of Proxy, so it’s rather unconvincing.
That said, with something like <https://github.com/littledan/proposal-new-initialize#another-use-case-simple-observed-classes-with-private https://github.com/littledan/proposal-new-initialize#another...>, something resembling the popular conception of Proxy might actually be made to work…
- NoahKAndrews 3y agoCan you elaborate on what's wrong with using then for other purposes?
- hajile 3y agoIf they didn’t want other use cases, they should have rethought the feature. The reality is that proxies came first. They see a LOT of use in reactive libraries making it very likely that your classes get passed into one these proxies (and breaking if private fields are used). They knew all this when ramrodding it through over the many protestors warning about this and other things. The fault is 100% on the hubris of the spec committee.