TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Use cases for ES6 proxies

83 pointsby inianalmost 9 years ago

9 comments

xpaulbettsxalmost 9 years ago
Here&#x27;s one way we&#x27;re using ES6 proxies at Slack:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;paulcbetts&#x2F;electron-remote" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;paulcbetts&#x2F;electron-remote</a><p>Create a proxy for an ES6 module that actually creates a separate process in a task pool and executes the method there.
iamleppertalmost 9 years ago
None of that code is any more clear, either conceptually or syntactically than a simply implemented and well designed library that does something purposeful and applied, like their &quot;application&quot; of handling validation.<p>And if you want &quot;private&quot; variables in javascript, just use a closure! Do people who write these blog posts even know basic javascript these days? If you really want all the features of java [said no one ever], than why don&#x27;t you just.....use java??<p>It&#x27;s just extra cruft we&#x27;re going to have to support now in our javascript runtimes.<p>&lt;&#x2F;slams door&gt;
评论 #12126966 未加载
评论 #12128211 未加载
评论 #12126998 未加载
评论 #12127392 未加载
cjhvealalmost 9 years ago
This is a great article. Proxies really have gotten lost in the hype around ES6. Surely it&#x27;s in part because JS developers have obvious pain points with async control flow and clumsy syntax, so things like generators and generous helpings of syntactic sugar are the most visible changes. However, I&#x27;m inclined to think that the level of abstraction and the complex API make it difficult for many developers to recognize their use cases or even play around with them.
评论 #12127569 未加载
jannesalmost 9 years ago
I think another reason is that ES6 proxies are impossible to polyfill.<p>My favorite use case would be Facebook&#x27;s immutable library[1], which uses awkward set(), setIn() and updateIn() methods for changing its data structures. But as an ES5+ library it wouldn&#x27;t want to require the consuming code to do ES6 transpilation.<p>[1]: <a href="https:&#x2F;&#x2F;facebook.github.io&#x2F;immutable-js&#x2F;" rel="nofollow">https:&#x2F;&#x2F;facebook.github.io&#x2F;immutable-js&#x2F;</a>
评论 #12128090 未加载
madeofpalkalmost 9 years ago
One use case for us was throwing an exception when accessing an undefined property, for a very specific part of our app. Made debugging loads easier.
zbjornsonalmost 9 years ago
A lot of these use cases are achievable using Object.defineProperty&#x2F;Properties. In most cases I think defineProperty even provides a nicer API because it&#x27;s per-property instead of per-trap. The &#x27;has&#x27; trap can&#x27;t be achieved completely with defineProperty (although you can make a property non-enumerable, which achieves the same goal in some cases).<p><a href="https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Object&#x2F;defineProperty" rel="nofollow">https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Refe...</a>
评论 #12130475 未加载
__salmost 9 years ago
I have an AI which spends a large portion of time cloning game state. I&#x27;d consider proxies to implement ergonomic copy-on-write if they were portable
评论 #12129500 未加载
scarlacalmost 9 years ago
&gt; This may be due to slow or limited support in Safari (no versions support it)<p>It&#x27;s worth noting that Safari Tech Preview actually does support it. It shows from the compatibility table that he links to. I also tested it just now, in Release 8.
lrsjngalmost 9 years ago
another great use case is dependency injection as seen in <a href="https:&#x2F;&#x2F;larsjung.de&#x2F;ghor&#x2F;" rel="nofollow">https:&#x2F;&#x2F;larsjung.de&#x2F;ghor&#x2F;</a>