Hacker News new | past | comments | ask | show | jobs | submit login

ES6 will introduce Maps and WeakMaps, at least, which addresses two and four; similarly, proxies will enable three.



WeakMaps don't quite give you everything that weak references do in other languages. Sometimes weak refs can be used to check if the object referred to has gone away (the weak ref becomes null in that case), that is not possible with WeakMaps. You also cannot create a list of weak references and iterate over them with a WeakMap.

There has been some discussion about adding more powerful weak refs to JavaScript, but I'm not sure where that discussion stands.


I wrote a parenthetical about weak references. I wonder why I deleted it. In short: weakrefs are unlikely to appear any time soon in ES, as they open up all kinds of fun around cross-origin objects (being able to detect their approximate life-time, and that's a fairly major side-channel attack) in some lovely edge-cases.


If you have any more details about this, or even if you don't, please post to es-discuss about it. Currently there is broad consensus on TC39 to add weak references in JS in the future.


I was imprecise; Lua has weak tables, not general weak references. So I'd be happy with weak maps in JS.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: